ackson-annotations-2.9.6.jar
jackson-core-2.9.6.jar
jackson-databind-2.9.6.jar
jackson-datatype-jdk8-2.9.6.jar
jackson-datatype-jsr310-2.9.6.jar
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "@class")
public abstract class ContractData {
public String toJSON() {
try {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JavaTimeModule());
return new ObjectMapper().writeValueAsString(this);
}
catch (JsonProcessingException ex) {
throw new IllegalStateException("unable to write data as json", ex);
}
}
public static ContractData fromJSON(String json) {
try {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JavaTimeModule());
return mapper.readValue(json, ContractData.class);
}
catch (IOException ex) {
throw new IllegalArgumentException("unable to convert json", ex);
}
}
}
public final class RegistrationContractData
extends ContractData
implements Serializable {
public static final long serialVersionUID = 1L;
private LocalDateTime created;
public RegistrationContractData() { }
public LocalDateTime getCreated() {
return this.created;
}
public void setCreated(LocalDateTime created) {
this.created = created;
}
}
"@class":"mypackage.contracts.data.RegistrationContractData","created":{"year":2018,"month":
"JULY","monthValue":7,"dayOfMonth":20,"hour":20,"minute":3,"second":33,"nano":653000000,"dayOfWeek":"FRIDAY","dayOfYear":201,"chronology":{"calendarType":"iso8601","id":"ISO"}}}
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string.
at [Source: (String)"{"@class":"mypackage.contracts.data.RegistrationContractData","created":{"year":2018,"month":"JULY","monthValue":7,"dayOfMonth":20,"hour":20,"minute":3,"second":33,"nano":653000000,"dayOfWeek":"FRIDAY","dayOfYear":201,"chronology":{"calendarType":"iso8601","id":"ISO"}}}"; line: 1, column: 95] (through reference chain: mypackage.contracts.data.RegistrationContractData["created"])
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1342) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1138) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.datatype.jsr310.deser.JSR310DeserializerBase._handleUnexpectedToken(JSR310DeserializerBase.java:99) ~[jackson-datatype-jsr310-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer.deserialize(LocalDateTimeDeserializer.java:141) ~[jackson-datatype-jsr310-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer.deserialize(LocalDateTimeDeserializer.java:39) ~[jackson-datatype-jsr310-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:127) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:189) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:161) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:130) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:97) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:254) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer.deserialize(TypeWrappedDeserializer.java:68) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3004) ~[jackson-databind-2.9.6.jar:2.9.6]
at mypackage.contracts.data.ContractData.fromJSON(ContractData.java:36) ~[tx-core.jar:na]
... 45 common frames omitted
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime created;
{"@class":"mypackage.contracts.data.RegistrationContractData","created":[2018,7,20,20,9,20,938000000]}