我有一个类如下。在Spring中将Requestbody映射到JSONObject
class ExampleBean{
public String Name;
public JSONObject data;
}
,我有@GET处理程序是如下:
@GET
@Consumes({MediaType.APPLICATION_JSON})
public Response getData(ExampleBean dataBean)
{
// some usage code here
}
我想下面的JSON映射到ExmampleBean:
{
"Name":"Example",
"data":{
"hello":"world",
"some":"value"
}
}
一切完美,如果data
是类型有两个公共字段名为hello
和some
。但由于data
是一个JSONObject,它实际上没有这些字段或相关设置程序,所以它最终抛出Unrecognized field "hello" (Class JSONObject), not marked as ignorable at [Source: [email protected]; line: 31, column: 18]
'地图<字符串,对象>'的JSON对象? – chrylis
我已经成功地将'JsonNode'映射到了顶层。当你把你的jsonobject改成jsonnode时它工作吗? –