问题:一开始是这样定义的
class TempData {
@JsonProperty("Count")
private String Count;
@JsonProperty("Time")
private String Time;
public TempData() {
}
public String getCount() {
return Count;
}
public void setCount(String count) {
Count = count;
}
public String getTime() {
return Time;
}
public void setTime(String time) {
Time = time;
}
}
但是在转换的时候抛出异常信息
com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class com.yolipai.wifi.server.statisticsV2.impl.PassengerFlowServiceImpl$TempData]: can not instantiate from JSON object (need to add/enable type information?)
at [Source: java.io.StringReader@66689699; line: 1, column: 3]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1078)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:268)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:124)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:227)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:204)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:23)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2986)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2105)
at com.yolipai.wifi.utils.JsonUtil.jsonToObject(JsonUtil.java:94)
解决方案:在class 前加上static,把它变为静态内部类即可解决问题