@Target(value={ANNOTATION_TYPE,METHOD,FIELD,TYPE,PARAMETER}) @Retention(value=RUNTIME) public @interface JsonSerializeAs
Classes) or on properties (property accessors
like "getters", "setters" and constructor parameters).
Overrides can apply to:
value itself (for all types and properties)
content of structured types (array and Collection
elements; Map values)
keys of Maps
To indicate that no override is to be used, Void.class is used
as the marker (will use declared type) -- this is necessary as Annotation
properties cannot have null values.
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;
}
| Modifier and Type | Optional Element and Description |
|---|---|
Class<?> |
content
Type to serialize content entries (array and
Collection
elements, Map values) as, instead of type declared. |
Class<?> |
key
Type to serialize
Map keys as, instead of type declared. |
Class<?> |
value
Type to serialize values as, instead of type declared.
|
public abstract Class<?> value
Bogus type Void is used to indicate that declared
type is used as-is (i.e. this annotation property has no setting).
public abstract Class<?> content
Collection
elements, Map 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 Void is used to indicate that declared
type is used as-is (i.e. this annotation property has no setting).
public abstract Class<?> key
Map keys 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 Void is used to indicate that declared
type is used as-is (i.e. this annotation property has no setting).
Copyright © 2008–2026 FasterXML. All rights reserved.