我需要向网络服务发送帖子请求,但它在异常后返回。
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();
}
}
服务器错误指示它不需要对象数组。删除此代码
JSONArray jsarray = new JSONArray();
jsarray.add(obj);
我尝试使用jacksonapi解析json,并提供以下详细信息。但我错了。请查找以下代码和堆栈跟踪的详细信息。 JSON 控制器类 下面这个类是我的bean类。PublisheData.java 发布数据列表.java 我收到以下错误。
下面是POJO类: 主要功能如下:
问题内容: 我正在尝试将json请求解析为模型。我不知道这段代码有什么问题。json的语法看起来正确,并且在Java模型上也有注释。我不知道为什么会出现如下错误: Java模型: 杰森代码: 问题答案: 您已声明为单个对象,但是将其作为JSON文档中多个对象的数组返回。 您的模型当前将parameters节点定义为一个对象: 这意味着您的模型对象需要一个如下所示的JSON文档: 但是在JSON文档
我试图将我的json请求解析到我的模型。我不知道,这段代码有什么问题。json的语法看起来是正确的,Java模型上的注释也是正确的。我不知道为什么会出现这样的错误: 爪哇模型: json代码:
我在下面有这个查询,它返回对象“消耗”列表。我在JSON反序列化期间收到错误,请参阅下面的第二种方法。 这是例外 请问,有什么帮助吗?