Skip to content

Instantly share code, notes, and snippets.

@sscovil
sscovil / Asset.java
Created February 3, 2014 17:31
This is the correct implementation of @JsonTypeInfo and related annotations when performing polymorphic JSON deserialization on an embedded interface property. It also illustrates the use of an Enum as a type name. See StackOverflow question: http://stackoverflow.com/questions/21485923/java-jackson-polymorphic-json-deserialization-of-an-object-w…
public class Asset {
private AssetType type;
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXTERNAL_PROPERTY,
property = "type"
)
@JsonSubTypes({
@JsonSubTypes.Type(value = ImageAssetProperties.class, name = "image"),