I have the following value object class
public class Data {
private Long id;
public Data() {
}
public Data(final Long id) {
this.id = id;
}
public Optional<Long> getId() {
return Optional.fromNullable(this.id);
}
public void setId(final Long id) {
this.id = id;
}
@Override
public int hashCode() { ... }
@Override
public boolean equals(final Object obj) { ... }
@Override
public String toString() { ... }
}The id property being optional (available for values that are already stored in the DB but not for new ones).
When I try to post (or put) such data, Jackson throws an error:
com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of long out of START_OBJECT token
at [Source: org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@1b0e0936; line: 1, column: 2] (through reference chain: com.acomplii.rs.Data["id"])
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:749)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer._parseLong(StdDeserializer.java:460)
This is because the getter for id is optional (an Object) while the setter itself is long (a scalar value).
This code was working through out the 0.7.x series and early 0.8-SNAPSHOTs before the upgrade to Jersey 2 (and Jackson 2.4 I think).