如果您需要在通用列表中读取 json,请执行类似的操作
{
Employee:
[
{
"key": "value",
"key": "value"
},
{
"key": "value",
"key": "value"
}
]
}
你的 json 列表对象和你的 bean 类是
class person {
private String key;
private String value;
}
现在您可以使用 HashMap 读取此 json
就像是
TypeReference<HashMap<String,List<Person>>> personList = new TypeReference<HashMap<String, List<Person>>>() {};
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
HashMap<String, List<Person>> employees = objectMapper.readValue(request.getInputStream(), personList);