将json映射到java对象时的异常包括map

时间:2016-05-19 11:53:48

标签: java json jackson

这是我想要将json映射到它的java对象:

public class ServiceResult {
   private String status;
   private Map<String, MNOFindSubOutPutData> result;
  }

 public class MNOFindSubOutPutData {
     private String status;
     private Subscriber result;
  }
@JsonSerialize(include=JsonSerialize.Inclusion.NON_DEFAULT)
public class Subscriber implements Serializable {
private String msisdn;  
private Integer latestStatusId; 
}

这是我的json字符串:

{"status":"success","result":{"123":{"status":"success","result": {"msisdn":"123","latestStatusId":8}}}

我的代码使用org.codehaus.jackson.map.ObjectMapper;

ObjectMapper mapper = new ObjectMapper();
ServiceResult sr=new ServiceResult();
try {
    sr = mapper.readValue(json,sr.getClass());
} catch (JsonParseException e) {
}

然后在运行时给我这个例外:

org.codehaus.jackson.map.JsonMappingException: Can not find a (Map) Key deserializer for type [simple type, class com.channelit.advoice.domain.entity.PrivilegeGroup]

我不知道这个班级的关系是什么(PrivilegeGroup)!!

我正在使用jackson-all-1.9.0.jar,请帮帮我

0 个答案:

没有答案