Jackson Json解析.json来映射错误

时间:2012-05-16 14:06:46

标签: java json jackson

我有一个制作好的 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: Can not find a (Map) Key deserializer for type [simple type, class com.tommaso.sample.D]
    at org.codehaus.jackson.map.deser.StdDeserializerProvider._handleUnknownKeyDeserializer(StdDeserializerProvider.java:430)
    at org.codehaus.jackson.map.deser.StdDeserializerProvider.findKeyDeserializer(StdDeserializerProvider.java:199)
    at org.codehaus.jackson.map.deser.BasicDeserializerFactory.createMapDeserializer(BasicDeserializerFactory.java:374)
    at org.codehaus.jackson.map.deser.StdDeserializerProvider._createDeserializer(StdDeserializerProvider.java:380)
........

我该怎么做才能解决它?

0 个答案:

没有答案