Web Services 无法反序列化示例,START_ARRAY标记不足

xpcnnkqh  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(130)

我需要向Web服务发送发布请求,但它返回以下异常

java.io.IOException: Server returned HTTP response code: 500 for URL domain.com

实际的服务器响应如下:

<html>
<head><title>500 Servlet Exception</title></head>
<body>
<h1>500 Servlet Exception</h1>
<code><pre>
<script language='javascript' type='text/javascript'>
function show() { document.getElementById('trace').style.display = ''; }
</script>
<a style="text-decoration" href="javascript:show();">[show]</a> org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance
of com.domain.service.beans.spec.SearchSpec out of START_ARRAY token
 at [Source: com.caucho.server.connection.ServletInputStreamImpl@7aafd4d3; line: 1, column: 1]
<span id="trace" style="display:none">
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance
of com.domain.service.beans.spec.SearchSpec out of START_ARRAY token
 at [Source: com.caucho.server.connection.ServletInputStreamImpl@7aafd4d3; line: 1, column: 1]
    at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
    at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:219)
    at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:212)
    at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromArray(BeanDeserializer.java:875)
    at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:597)
    at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2732)
    at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1923)
    at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.readInternal(MappingJacksonHttpMessageConverter.java:135)
    at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:154)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.readWithMessageConverters(HandlerMethodInvoker.java:643)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveRequestBody(HandlerMethodInvoker.java:607)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:346)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:427)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:415)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:788)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:153)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:91)
    at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:103)
    at com.domain.service.filter.LoggingFilter.doFilter(LoggingFilter.java:91)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)
    at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:187)
    at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:265)
    at com.caucho.server.hmux.HmuxRequest.handleRequest(HmuxRequest.java:436)
    at com.caucho.server.port.TcpConnection.run(TcpConnection.java:682)
    at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:743)
    at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:662)
    at java.lang.Thread.run(Thread.java:662)
</span>
</pre></code>
</body></html>

我根据以下内容发送请求

Method: POST
This returns a list of products
Dates are optional.
Destination ID and currencyCode are required.
JSON Request Parameters
{

"startDate":"2013-10-25", "endDate":"2013-10-27", "topX":"1-5", "destId":684, "currencyCode":"EUR", "catId":0,
"subCatId":0, "dealsOnly":false, "sortOrder":"PRICE_FROM_A"
}

so r t O r d e r
Valid sort orders:
TOP_SELLERS - The top sellers - default sortOrder 
REVIEW_AVG_RATING_A - Traveler Rating (low->high) Average 
REVIEW_AVG_RATING_D - Traveler Rating (high->low) Average 
PRICE_FROM_A - Price (low->high)
PRICE_FROM_D - Price (high->low)

topX
For returning results in particular positions. e.g. a value of 11-15 will return the results in position 11 to 15 based on the sort (total of 5 products). Useful for pagination.

catId
Category id from the /service/taxonomy/categories

subCatId
Sub Category id from the /service/taxonomy/categories

dealsOnly
Applicable only when there is no startDate/endDate as it is a destionation search only feature. This API is used for obtaining lists of products for destination pages.

我的代码

public void Search() {

        JSONObject obj = new JSONObject();
        obj.put("startDate", "2014-08-25");
        obj.put("endDate", "2014-08-25");
        obj.put("topX", "1-5");
        obj.put("destId", 684);
        obj.put("currencyCode", "EUR");
        obj.put("catId", 21);
        obj.put("subCatId", 78);
        obj.put("dealsOnly", false);
        obj.put("sortOrder","PRICE_FROM_A");

        JSONArray jsarray = new JSONArray();
        jsarray.add(obj);
        putDataToServer(jsarray.toJSONString());

    }

    public void putDataToServer(String returnedJObject) {

try{
        java.lang.String contentToPost = returnedJObject;

        java.net.URLConnection connection = new java.net.URL("domain.com").openConnection();

        connection.setUseCaches(true);
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestProperty("Content-Length", "" + contentToPost.length());

        connection.setRequestProperty("Content-Type", "application/json");
        connection.setRequestProperty("Cache-Control", "no-cache");

        java.io.OutputStream stream = connection.getOutputStream();
        stream.write(contentToPost.getBytes());
        stream.close();
        System.err.println("request is sent");

        BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        System.err.println(br.readLine());
        br.close();

    }catch(Exception e){
            e.printStackTrace();
            }
    }
wz8daaqr

wz8daaqr1#

服务器错误指示它不需要对象数组。请删除此代码

JSONArray jsarray = new JSONArray();
jsarray.add(obj);

相关问题