You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given the types MySuperDto, MySubDto, MyEmptySubDto, see below.
For version 1 the super type added a the field superField, but was empty at version 0.
Reading this Json, at version 0, with a reader for the super type MySuperDto
{
"type" : "MyEmptySubDto"
}
will fail throwing
com.fasterxml.jackson.databind.JsonMappingException: value must be a JSON object
at [Source: (String)"{
"type" : "MyEmptySubDto"}"; line: 2, column: 27]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:274)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:1844)
at com.github.jonpeterson.jackson.module.versioning.VersionedModelDeserializer.deserialize(VersionedModelDeserializer.java:75)
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:130)
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:97)
at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:254)
at com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer.deserialize(TypeWrappedDeserializer.java:68)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4218)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3214)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3182)
Details on sub types
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type"
)
@JsonSubTypes({
@JsonSubTypes.Type(value = MySubDto.class, name = "MySubDto"),
@JsonSubTypes.Type(value = MyEmptySubDto.class, name = "MyEmptySubDto")
})
@JsonVersionedModel(
currentVersion = "1",
defaultDeserializeToVersion = "0",
toCurrentConverterClass = ToCurrentMySuperDto.class)
static abstract class MySuperDto {
@JsonProperty(required = true)
public String superField;
@JsonCreator
public MySuperDto(
@JsonProperty(required = true, value = "superField") String superField
) {
this.superField = superField;
}
}
static class MySubDto extends MySuperDto {
@JsonProperty
String subField;
@JsonCreator
public MySubDto(
@JsonProperty(required = true, value = "superField") String superField,
@JsonProperty(required = true, value = "subField") String subField
) {
super(superField);
this.subField = subField;
}
}
static class MyEmptySubDto extends MySuperDto {
@JsonCreator
public MyEmptySubDto(
@JsonProperty(required = true, value = "superField") String superField
) {
super(superField);
}
}
The text was updated successfully, but these errors were encountered:
Given the types
MySuperDto
,MySubDto
,MyEmptySubDto
, see below.For version 1 the super type added a the field
superField
, but was empty at version 0.Reading this Json, at version 0, with a reader for the super type
MySuperDto
will fail throwing
Details on sub types
The text was updated successfully, but these errors were encountered: