我需要一些帮助Jackson图书馆在 java 。我有以下课程:
@JsonIgnoreProperties(ignoreUnknown = true)
public class MarketHistoryData {
private String countryCode;
@JsonDeserialize(keyUsing = BpTimeDeserializer.class)
private Map<BpTime, Double> hourToExpectedEngagePaidListings;
@JsonDeserialize(keyUsing = BpTimeDeserializer.class)
private Map<BpTime, Double> hourMinuteToExpectedEngagePaidListings;
public MarketHistoryData() {}
...
// getters and setters
}
我知道jackson很难反序列化一个键是对象的Map。因此,我添加了注解:
@JsonDeserialize(keyUsing = BpTimeDeserializer.class)
bptimedeserializer类是:
public class BpTimeDeserializer extends KeyDeserializer {
private ObjectMapper mapper = new ObjectMapper();
@Override
public BpTime deserializeKey(String key, DeserializationContext ctxt) throws IOException {
return mapper.readValue(key, BpTime.class);
}
}
不过,在反序列化过程中我还是遇到了一个错误:
*****.uncheckedexecutionexception:com.fasterxml.jackson.databind.jsonmappingexception:无法识别的标记“com”:在[source:(string)处应为(json string、number、array、object或标记“null”、“true”或“false”)****bptime@5922062e[小时=1,分钟=0]“;行:1,列:1](通过引用链:**PACERCYCLOUTPUT[“campaignidtofactorcomputationdata”]->java.util.linkedhashmap[“1011620661”]->***factorcomputationdata[“selectedmarkethistorydataforcampaign”]->***markethistorydata[“HourtExpectedEngagePaidListings”])
你知道我能做些什么来克服这个错误吗?
1条答案
按热度按时间rbpvctlc1#
我终于找到了解决这个错误的方法。