我有一个制作精良的json 输入文件。
我有这些对象:
@JsonIgnoreProperties(ignoreUnknown = true)
public class A {
private B b;
//getter and setter of b
...
}
@JsonIgnoreProperties(ignoreUnknown = true)
public class B {
private List<C> cList = new ArrayList<C>();
//getter and setter of cList
...
}
@JsonIgnoreProperties(ignoreUnknown = true)
public class C {
private Map<D,Integer> dMap = new HashMap<D,Integer>();
//getter and setter of dMap
...
}
@JsonIgnoreProperties(ignoreUnknown = true)
public class D {
private String name;
//getter and setter of name
...
}
之后我有一个主要课程
....
A a = null;
try {
String path = "/home/tommaso/file-in.json";
ObjectMapper mapper = new ObjectMapper();
a = mapper.readValue(new File(path), A.class);
} catch (JsonGenerationException ex) {
Logger.getLogger(CroweSolver.class.getName()).log(Level.SEVERE, null, ex);
} catch (JsonMappingException ex) {
Logger.getLogger(CroweSolver.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(CroweSolver.class.getName()).log(Level.SEVERE, null, ex);
}
....
当我启动代码时,我有这个异常:
org.codehaus.jackson.map.JsonMappingException:找不到类型[简单类型,类com.tommaso.sample.D]的(映射)键反序列化器 在 org.codehaus.jackson.map.deser.StdDeserializerProvider._handleUnknownKeyDeserializer(StdDeserializerProvider.java:430) 在 org.codehaus.jackson.map.deser.StdDeserializerProvider.findKeyDeserializer(StdDeserializerProvider.java:199) 在 org.codehaus.jackson.map.deser.BasicDeserializerFactory.createMapDeserializer(BasicDeserializerFactory.java:374) 在 org.codehaus.jackson.map.deser.StdDeserializerProvider._createDeserializer(StdDeserializerProvider.java:380) ...........
我应该怎么做才能解决它?