0

我正在尝试使用带有 RESTful 和 JSON 的 Web 服务。

这是我的 POST 方法:

@POST
public Response setCustomerInvoiceNotifications(SetCustomerInvoiceNotificationsRequestBO requestBO, @Context HttpHeaders hh) throws JSONException, Exception {
   init(config);

    Response response = null;
    ResultBO resultBO = (ResultBO) roalCache.callService("setCustomerInvoiceNotifications", requestBO, true);
    if (resultBO != null) {
        if (resultBO.getResult() != null) {

            SetCustomerInvoiceNotificationsResponseBO responseBO = (SetCustomerInvoiceNotificationsResponseBO)resultBO.getResult();
            ObjectFactory factory = new ObjectFactory();
            JSONObject jsonObject = new JSONObject(responseBO); 
            String result = "@Produces(\"application/json\") Output: \n\n Output: \n\n" + jsonObject;
            response = Response.status(200).cookie(cookie).entity(result).build();
        } else if (resultBO.getCause() != null) {
            JSONObject jsonObject = new JSONObject(resultBO.getCause());
            logger.debug("[{}]  jsonObject.toString = ",  jsonObject.toString() );
            String result = "@Produces(\"application/json\") Output: \n\n Output: \n\n" + jsonObject;  
            logger.debug("[{}]  jsonObject result = ",  result );
            response = Response.status(500).cookie(cookie).entity(result).build();  
        }
    }      
    return response;
}   

我正在使用带有数组的 JSON:

[{
    "correlationId": "12345432",
    "customerId": "8508871",
    "notificationWhenIssued": {
        "destinations": {
            "channel": "email",
            "address": "razvan.nicolae90@yahoo.com"
        }
    },
    "notificationBeforeDueDate": {
        "destinations": {
            "channel": "email",
            "address": "razvan.nicolae90@yahoo.com"
        },
        "daysBeforeDueDate": "2"
    }
}]

发布 JSON 后,我收到此消息错误:

{"message":"Can not deserialize instance of com.upc.portal.business.SetCustomerInvoiceNotificationsRequestBO 
out of START_ARRAY token\n at 
[Source: weblogic.servlet.internal.ServletInputStreamImpl@17ac5e2; line: 1, column: 1]",
"stackTrace":"[org.codehaus.jackson.map.JsonMappingException.from(Unknown Source)...
4

1 回答 1

0

我找到了我的问题的答案:

我刚刚将它添加到我的 web.xml 文件中:

<init-param>
    <param-name>com.sun.jersey.config.property.packages</param-name>
    <param-value>
     my.own.packages;
     org.codehaus.jackson.jaxrs</param-value>
</init-param>

我还包括一个罐子 - jackson-all-1.8.10

对于 json 输入文件的正确格式,这很好。

于 2013-11-12T07:46:11.937 回答