简体   繁体   中英

how to use json with jersey client to .net REST svc with weblogic?

My local tech stack is wl 9.2, jersey 1.1.5.1.

The remote REST svc is in ASP.net, and the response in the request body is described in a document as

{
    "Context" : 
    {
        "ID" : "0c351860a82d",        
        "Action" : "SomeAction",        
        "MessageID" : "5d220b792d7f",        
        "UriString" : "",        
        "ReferenceID" : "3ee8c695ffa5",        
        "Time" : "2009-02-11T01:37:44.52",        
        "ControlNbr" : "1.001"
    },    
    "Answer" : 
    {
        "Code" : 0,        
        "Detail" : ""
    },    
    "Exceptions" : [{
            "Code": 1,
            "Text": "Missing value ",
            "Trace": "trace from error.."
        },{
            "Code": 2,
            "Text": "Invalid input ",
            "Trace": "trace from error.."
        } ],   
    "Salt" : "196ac409",    
    "TmpKey" : "3ee8c695ffa5"
}

I've tried and mapped the above to POJOs that start like this:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class SvcResponseBean {

    public SvcResponseBean() {}

    @XmlElement(name="Context")
    public ContextBean ctx;

    @XmlElement(name="Answer")
    public AnswerBean answ;

    @XmlElement(name = "Exceptions")
    public List<ExceptionBean> exs = new ArrayList<ExceptionBean>();

    @XmlElement(name="Salt")
    public String salt;

    @XmlElement(name="TmpKey")
    public String tmpKey;

    public void add(ExceptionBean eb) {exs.add(eb);}
}

The owners of the svc can help me only so much and not much with Jersey. At runtime, the call

ClientResponse myClientResponse= myWebResourceBuilder.get(ClientResponse.class);
SvcResponseBeanpsrb = myClientResponse.getEntity(SvcResponseBean.class);

croaks with

java.lang.Error: Error: could not match input
at com.sun.jersey.json.impl.reader.JsonLexer.zzScanError(JsonLexer.java:468)
at com.sun.jersey.json.impl.reader.JsonLexer.yylex(JsonLexer.java:713)
at com.sun.jersey.json.impl.reader.JsonXmlStreamReader.nextToken(JsonXmlStreamReader.java:153)

Obviously, I'm not that well versed in JSON and Jersey, but I'm learning. Is there a way to make Jersey/JsonLexer tell me what exactly went wrong? I know there are a number of different types of JSON formats out there, so perhaps that's my problem?

Any hints would be appreciated.

karoy

Perhaps it's just a copy-and-paste error, but the following is not valid JSON:

"Exceptions" : {
    "Code": 1,
    "Text": "Missing value ",
    "Trace": "trace from error.."
},{
    "Code": 2,
    "Text": "Invalid input ",
    "Trace": "trace from error.."
}    
"Salt" : "196ac409"

There is no key associated with the value { "Code": 2, "Text", ... and there is nothing separating the } and "Salt" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM