Package com.fasterxml.jackson.annotation
Annotation Type JsonSerializeAs
-
@Target({ANNOTATION_TYPE,METHOD,FIELD,TYPE,PARAMETER}) @Retention(RUNTIME) public @interface JsonSerializeAsAnnotation to indicate override of intended serialization type; a more generic type (super-type) than declared one. Can be used on types (Classes) or on properties (property accessors like "getters", "setters" and constructor parameters). Overrides can apply to:valueitself (for all types and properties)contentof structured types (array andCollectionelements;Mapvalues)keys ofMaps
To indicate that no override is to be used,
Void.classis used as the marker (will use declared type) -- this is necessary as Annotation properties cannot havenullvalues.Example usage:
public class POJO { // ValueImpl extends GenericValue @JsonSerializeAs(GenericValue.class) public ValueImpl value; @JsonSerializeAs(keys = GenericKey.class, content = GenericValue.class) public Map<KeyImpl, ValueImpl> props; }
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description java.lang.Class<?>contentType to serialize content entries (array andCollectionelements,Mapvalues) as, instead of type declared.java.lang.Class<?>keyType to serializeMapkeys as, instead of type declared.java.lang.Class<?>valueType to serialize values as, instead of type declared.
-
-
-
Element Detail
-
value
java.lang.Class<?> value
Type to serialize values as, instead of type declared. Must be a super-type of declared type (or type itself); otherwise an exception may be thrown by serializer.Bogus type
Voidis used to indicate that declared type is used as-is (i.e. this annotation property has no setting).- Default:
- java.lang.Void.class
-
-
-
content
java.lang.Class<?> content
Type to serialize content entries (array andCollectionelements,Mapvalues) as, instead of type declared. Must be a super-type of declared type (or type itself); otherwise an exception may be thrown by serializer.Bogus type
Voidis used to indicate that declared type is used as-is (i.e. this annotation property has no setting).- Default:
- java.lang.Void.class
-
-
-
key
java.lang.Class<?> key
Type to serializeMapkeys as, instead of type declared. Must be a super-type of declared type (or type itself); otherwise an exception may be thrown by serializer.Bogus type
Voidis used to indicate that declared type is used as-is (i.e. this annotation property has no setting).- Default:
- java.lang.Void.class
-
-