Annotation Type JsonDeserializeAs


  • @Target({ANNOTATION_TYPE,METHOD,FIELD,TYPE,PARAMETER})
    @Retention(RUNTIME)
    public @interface JsonDeserializeAs
    Annotation to indicate override of deserialization target type; a more specialized type (sub-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:
    • 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 {
       @JsonDeserializeAs(ValueImpl.class)
       public Value value;
    
       @JsonDeserializeAs(keys = KeyEnum.class, content = ValueImpl.class)
       public Map<Object, Object> props;
     }
    
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      java.lang.Class<?> content
      Type to deserialize content entries (array and Collection elements, Map values) as, instead of type declared.
      java.lang.Class<?> keys
      Type to deserialize Map keys as, instead of type declared.
      java.lang.Class<?> value
      Type to deserialize values as, instead of type declared.
    • Element Detail

      • value

        java.lang.Class<?> value
        Type to deserialize values as, instead of type declared. Must be a sub-type of declared type; otherwise an exception may be thrown by deserializer.

        Bogus type Void is 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 deserialize content entries (array and Collection elements, Map values) as, instead of type declared. Must be a sub-type of declared type; otherwise an exception may be thrown by deserializer.

        Bogus type Void is used to indicate that declared type is used as-is (i.e. this annotation property has no setting).

        Default:
        java.lang.Void.class
      • keys

        java.lang.Class<?> keys
        Type to deserialize Map keys as, instead of type declared. Must be a sub-type of declared type; otherwise an exception may be thrown by deserializer.

        Bogus type Void is used to indicate that declared type is used as-is (i.e. this annotation property has no setting).

        Default:
        java.lang.Void.class