Annotation Type JsonProperty
-
@Target({ANNOTATION_TYPE,FIELD,METHOD,PARAMETER}) @Retention(RUNTIME) public @interface JsonPropertyMarker annotation that can be used to define a non-static method as a "setter" or "getter" for a logical property (depending on its signature), or non-static object field to be used (serialized, deserialized) as a logical property.Default value ("") indicates that the field name is used as the property name without any modifications, but it can be specified to non-empty value to specify different name. Property name refers to name used externally, as the field name in JSON objects.
Starting with Jackson 2.6 this annotation may also be used to change serialization of
Enumlike so:public enum MyEnum { @JsonProperty("theFirstValue") THE_FIRST_VALUE, @JsonProperty("another_value") ANOTHER_VALUE; }as an alternative to usingJsonValueannotation.Starting with Jackson 2.12 it is also possible to specify
namespaceof property: this property is only used by certain format backends (most notably XML).
-
-
Field Summary
Fields Modifier and Type Fields Description static intINDEX_UNKNOWNMarker value used to indicate that no index has been specified.static java.lang.StringUSE_DEFAULT_NAMESpecial value that indicates that handlers should use the default name (derived from method or field name) for property.
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description JsonProperty.AccessaccessOptional property that may be used to change the way visibility of accessors (getter, field-as-getter) and mutators (constructor parameter, setter, field-as-setter) is determined, either so that otherwise non-visible accessors (like private getters) may be used; or that otherwise visible accessors are ignored.java.lang.StringdefaultValueProperty that may be used to document expected default value for the property: most often used as source information for generating schemas (like JSON Schema or protobuf/thrift schema), or documentation.intindexProperty that indicates numerical index of this property (relative to other properties specified for the Object).java.lang.StringnamespaceOptional namespace to use with data formats that support such concept (specifically XML); if so, used withvalue()to construct fully-qualified name.booleanrequiredProperty that indicates whether a value (which may be explicit null) is expected for property during deserialization or not.java.lang.StringvalueDefines name of the logical property, i.e.
-
-
-
Element Detail
-
value
java.lang.String value
Defines name of the logical property, i.e. JSON object field name to use for the property. If value is empty String (which is the default), will try to use name of the field that is annotated. Note that there is no default name available for constructor arguments, meaning that Empty String is not a valid value for constructor arguments.- Default:
- ""
-
-
-
namespace
java.lang.String namespace
Optional namespace to use with data formats that support such concept (specifically XML); if so, used withvalue()to construct fully-qualified name.- Since:
- 2.12
- Default:
- ""
-
-
-
required
boolean required
Property that indicates whether a value (which may be explicit null) is expected for property during deserialization or not. If expected,BeanDeserializedshould indicate this as a validity problem (usually by throwing an exception, but this may be sent via problem handlers that can try to rectify the problem, for example, by supplying a default value).Note that as of 2.6, this property is only used for Creator Properties, to ensure existence of property value in JSON: for other properties (ones injected using a setter or mutable field), no validation is performed. Support for those cases may be added in future. State of this property is exposed via introspection, and its value is typically used by Schema generators, such as one for JSON Schema.
- Since:
- 2.0
- Default:
- false
-
-
-
defaultValue
java.lang.String defaultValue
Property that may be used to document expected default value for the property: most often used as source information for generating schemas (like JSON Schema or protobuf/thrift schema), or documentation. It may also be used by Jackson extension modules; core `jackson-databind` does not have any automated handling beyond simply exposing this value through bean property introspection.It is possible that in future this annotation could be used for value defaulting, and especially for default values of Creator properties, since they support
required()in 2.6 and above.- Since:
- 2.5
- Default:
- ""
-
-
-
access
JsonProperty.Access access
Optional property that may be used to change the way visibility of accessors (getter, field-as-getter) and mutators (constructor parameter, setter, field-as-setter) is determined, either so that otherwise non-visible accessors (like private getters) may be used; or that otherwise visible accessors are ignored.Default value os
JsonProperty.Access.AUTOwhich means that access is determined solely based on visibility and other annotations.- Since:
- 2.6
- Default:
- com.fasterxml.jackson.annotation.JsonProperty.Access.AUTO
-
-