我有一個JSON:無法與傑克遜反序列化JSON的lib
{
"firstField": "Something One",
"secondField": "Something Two",
"thirdField": [
{
"thirdField_one": "Something Four",
"thirdField_two": "Something Five"
},
{
"thirdField_one": "Something Six",
"thirdField_two": "Something Seven"
}
],
"fifthField": [
{
"fifthField_one": "Something… ",
"fifthField_two": "Something...",
"fifthField_three": 12345
},
{
"fifthField_one": "Something",
"fifthField_two": "Something",
"fifthField_three": 12345
}
]
}
我有我的課:
public static class MyClass {
@JsonProperty
private String firstField, secondField;
@JsonProperty
private ThirdField thirdField;
@JsonProperty
private FifthField fifthField;
public static class ThirdField {
private List<ThirdFieldItem> thirdField;
}
public static class ThirdFieldItem {
private String thirdField_one, thirdField_two;
}
public static class FifthField {
private List<FifthFieldItem> fifthField;
}
public static class FifthFieldItem {
private String fifthField_one, fifthField_two;
private int fifthField_three;
}
}
我與傑克遜庫反序列化他們:
public void testJackson() throws IOException {
JsonFactory factory = new JsonFactory();
ObjectMapper mapper = new ObjectMapper(factory);
File from = new File("text.txt"); // JSON I mentioned above
mapper.readValue(from, MyClass.class);
}
但我得到例外:
org.codehaus.jackson.map.JsonMappingException:無法反序列化主要$ MyClass的$ ThirdField的 實例出來START_ARRAY令牌