@Target(value={ANNOTATION_TYPE,FIELD,METHOD,PARAMETER}) @Retention(value=RUNTIME) public @interface JsonAlias
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"}.
public abstract String[] value
Copyright © 2008–2024 FasterXML. All rights reserved.