我张贴这样的事:邮政JSON数组到Spring引导RestController
{
"stuff": [
{
"thingId": 1,
"thingNumber": "abc",
"countryCode": "ZA"
},
{
"thingId": 2,
"thingNumber": "xyz",
"countryCode": "US"
}
]
}
我可以检索在控制器中的数据如下:
@RequestMapping(value = "/stuffs", method = RequestMethod.POST)
public String invoices(@RequestBody Map<String, List <Stuff>> stuffs) {
return "Hooray";
}
我很想do只是将一个List of Stuff传入控制器;即:
@RequestMapping(value = "/stuffs", method = RequestMethod.POST)
public String invoices(@RequestBody List <Stuff> stuffs) {
return "I'm sad that this won't work.";
}
但是,杰克逊不喜欢这个。我得到的错误是:
无法读取JSON文件:在[来源无法反序列化 java.util.ArrayList中的实例进行START_OBJECT令牌的\ n: [email protected];行:1,列:1];嵌套0异常是com.fasterxml.jackson.databind.JsonMappingException:可以 不反序列化java.util.ArrayList的实例超出START_OBJECT token [n] [Source:[email protected];行:1, 列:1]
我不能在以下发送(因为它不是有效的JSON):
{
[
{
"thingId": 1,
"thingNumber": "abc",
"countryCode": "ZA"
},
{
"thingId": 2,
"thingNumber": "xyz",
"countryCode": "US"
}
]
}
我敢肯定,这是简单的东西,但我不能蒸馏的从我的StackOverflow和谷歌搜索答案。
任何帮助,将不胜感激! :)
是的!一旦时间限制通过,我会选择这个作为接受的答案。你从一些巨大的挫折中拯救了我! – orrymr
很高兴我能帮上忙 –