我有一个类似下面的JSON。
{
"id": 123,
"screenId": "abc456",
"name": "Screen1",
"description": "screen description",
"format": [
{
"sectionName": "fontType",
"font": {
"family": {
"id": "TIMESNEWROMAN",
"description": "TIMESNEWROMAN"
}
}
},
{
"sectionName": "backgroundColorPanel",
"color": "#000000"
},
{
"sectionName": "buttonBorderShape",
"shape": {
"color": "#000000",
"type": {
"id": "SOLID",
"description": "Solid"
},
"size": "12"
}
}
]
}
我尝试使用以下代码将其转换为List<Object[]>
,但我得到了异常
代码:
JsonNode node = mapper.readTree(jsonString);
TypeReference<List<Object[]>> typeRef = new TypeReference<List<Object[]>>(){};
List<Object> list = mapper.readValue(node.traverse(), typeRef);
例外:
Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
我也试过以下
mapper.readValue(mapper.treeAsTokens(jsonString), TypeFactory.defaultInstance().constructCollectionType(ArrayList.class, Object[].class))
但我得到同样的例外。有人能帮助我吗?