我正在将Spring 3.1.x应用程序升级到Spring 4.2.x.我已经更换了所有的jar,修复了任何代码/配置问题,现在可以启动应用程序了。将JSON请求发布到Spring控制器时会出现问题。我收到错误:
val data: DataSet[(String, Int)]
data.output(new DiscardingOutputFormat[(String, Int)]())
使用Chrome的开发人员工具,我可以看到JSON请求有效负载实际上是使用ASCII字符发送的,第一个字符是“%”符号。但是,ASCII编码的字符串是有效的JSON!
org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Unexpected character ('%' (code 37)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
我的XML配置中没有对“标准”注释驱动标记的任何自定义。这是我的控制器方法的样子:
Request URL:http://localhost:8080/edge2/app/search/searchResults.ajax
Request Method:POST
Status Code:400 Bad Request
Remote Address:[::1]:8080
Response Headers
Cache-Control:no-cache, no-store, max-age=0, must-revalidate
Connection:close
Content-Language:en
Content-Length:968
Content-Type:text/html;charset=utf-8
Date:Mon, 07 Dec 2015 14:16:09 GMT
Expires:0
Pragma:no-cache
Server:Apache-Coyote/1.1
X-Content-Type-Options:nosniff
X-Frame-Options:DENY
X-XSS-Protection:1; mode=block
Request Headers
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,de;q=0.6
Connection:keep-alive
Content-Length:560
Content-Type:application/json; charset=UTF-8
Cookie:JSESSIONID=A1ED0AC2F3960170E9000FAB1E5FBD45
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/edge2/app/search.htm
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36
X-Requested-With:XMLHttpRequest
Request Payload
%7B%22quoteNumber%22%3A%22%22%2C%22quoteRevision%22%3A%22%22%2C%22createdDateBegin%22%3A%2209%2F07%2F2015%22%2C%22createdDateEnd%22%3A%22%22%2C%22quoteDescription%22%3A%22%22%2C%22productDescription%22%3A%22%22%2C%22productCategory%22%3A%22%22%2C%22customerName%22%3A%22%22%2C%22shipToName%22%3A%22%22%2C%22contactLastName%22%3A%22%22%2C%22soldToNumber%22%3A%22%22%2C%22primarySales%22%3A%22%22%2C%22csrName%22%3A%22%22%2C%22materialNumber%22%3A%22%22%2C%22proposalStatus%22%3A%22REDY%22%2C%22proposalType%22%3A%22%22%2C%22userRole%22%3A%22Administrator%22%7D=
我的类路径中有Jackson库(2.6.3)。以下是Ajax请求的样子:
@RequestMapping(value="/searchResults.ajax", method = RequestMethod.POST)
public @ResponseBody ArrayList<String> showSearchResults(@RequestBody SearchForm searchForm)
getJSONForm只是创建一个Javascript对象并为参数创建名称/值对。
答案 0 :(得分:2)
我认为您的问题在于Json有效负载,我将您的有效负载放在我得到的URLDecoder中:
public void sumbit(ActionEvent e) {
char[] pswd = password.getValue().toCharArray();
............
}
注意有效负载末尾的 = 字符。
在此站点中,您可以放置有效负载并获取已解码的JSon String。 http://meyerweb.com/eric/tools/dencoder/
我建议您尝试从RestClient调用您的服务,例如:
https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo
或
https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop