Top Description Methods
com.fasterxml.jackson.annotation

public @Interface JsonAlias

extends Annotation
Annotations
@Target:ANNOTATION_TYPE, FIELD, METHOD, PARAMETER
@Retention:RUNTIME
@JacksonAnnotation
Imports
java.lang.annotation.ElementType, .Retention, .RetentionPolicy, .Target

Annotation that can be used to define one or more alternative names for a property, accepted during deserialization as alternative to the official name. Alias information is also exposed during POJO introspection, but has no effect during serialization where primary name is always used.

Examples:

public class Info {
  @JsonAlias({ "n", "Name" })
  public String name;
}

Note

Order of alias declaration has no effect. All properties are assigned in the order they come from incoming JSON document. If same property is assigned more than once with different value, later will remain. For example, deserializing

 public class Person {
    @JsonAlias({ "name", "fullName" })
    public String name;
 }
 
from
 { "fullName": "Faster Jackson", "name": "Jackson" }
 
will have value "Jackson".

Also, can be used with enums where incoming JSON properties may not match the defined enum values. For instance, if you have an enum called Size with values SMALL, MEDIUM, and LARGE, you can use this annotation to define alternate values for each enum value. This way, the deserialization process can map the incoming JSON values to the correct enum values.

Sample implementation:

public enum Size {
     @JsonAlias({ "small", "s", "S" })
     SMALL,

     @JsonAlias({ "medium", "m", "M" })
     MEDIUM,

     @JsonAlias({ "large", "l", "L" })
     LARGE
 }

During deserialization, any of these JSON structures will be valid and correctly mapped to the MEDIUM enum value: {"size": "m"}, {"size": "medium"}, or {"size": "M"}.

Since
2.9

Method Summary

Modifier and TypeMethod and Description
public String[]

Returns:

Zero or more aliases to associate with property annotated
value
()

One or more secondary names to accept as aliases to the official name.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public String[] value()

One or more secondary names to accept as aliases to the official name.

Returns:String[]

Zero or more aliases to associate with property annotated