如何使用json与泽西客户端.net REST svc与weblogic?

时间:2021-10-07 19:34:53

My local tech stack is wl 9.2, jersey 1.1.5.1.

我的本地技术堆栈是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

远程REST svc在ASP.net中,请求正文中的响应在文档中描述为

{
    "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:

我已经尝试将上面的内容映射到以这样开头的POJO:

@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

svc的所有者可以帮助我这么多,而不是泽西。在运行时,调用

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?

显然,我不是那么精通JSON和泽西岛,但我正在学习。有没有办法让Jersey / JsonLexer告诉我到底出了什么问题?我知道有很多不同类型的JSON格式,所以也许这就是我的问题?

Any hints would be appreciated.

任何提示将不胜感激。

karoy

1 个解决方案

#1


0  

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

也许这只是一个复制粘贴错误,但以下是无效的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".

没有与值{“Code”:2,“Text”,...相关联的键,并且没有任何东西将}和“Salt”分开。

#1


0  

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

也许这只是一个复制粘贴错误,但以下是无效的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".

没有与值{“Code”:2,“Text”,...相关联的键,并且没有任何东西将}和“Salt”分开。