我已经基于这个类创建了一个带有杰克逊的 JSON:
public class One {
public long param;
public List<Two> two;
public static class Two{
public long param;
public List<Short> param2;
}
}
我为每个类定义了两个构造函数,并使用它来创建稍后写入 json 文件的对象。结果是(有效的 JSON):
[{"param":1,"Two":[{"param":4,"param2":[1,2,3]},{"param":5,"parma2":[4,5,6]}]},{"param":2,"Two":[{"param":6,"param2":[1,2,3]}]}]
现在我想读取并加载参数并定义:
mapper.configure(Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); //tried with and without
JsonFactory f = new JsonFactory();
JsonParser jp;
jp = f.createJsonParser(FILE);
jp.nextToken();
while (jp.nextToken() == JsonToken.START_OBJECT) {
mapper.readValue(jp, One.class);
}
jp.close();
我有这个错误:
Can not deserialize instance of json.One$Two out of START_ARRAY