Spring不会反序列化json字符串(不带引号的属性)

时间:2013-04-22 20:38:33

标签: java spring-mvc

Spring发送json数组时抛出错误。我不确定我在这里缺少什么。

RequestBody

{
"deliverySessionId":"c1fb327b-98a8-46d4-9e82-ce7507b5be93",
imageNames: ["name1", "name2"]
}

端点

@RequestMapping(value = { "/examImages/" }, method = { RequestMethod.POST } )
public @ResponseBody ImageResponseCommand streamExamImages( @RequestBody ImageResponseCommand imageResponseCommand ) {

错误

 The request sent by the client was syntactically incorrect.

如果我的请求不包含imageNames属性,它可以正常工作。

  { "deliverySessionId":"c1fb327b-98a8-46d4-9e82-ce7507b5be93" }

1 个答案:

答案 0 :(得分:5)

您的JSON字符串格式不正确。对象键需要用引号括起来。

{
    "deliverySessionId":"c1fb327b-98a8-46d4-9e82-ce7507b5be93",
    "imageNames": ["name1", "name2"]
}