Package com.fasterxml.jackson.annotation
Annotation Type JsonFormat
-
@Target({ANNOTATION_TYPE,FIELD,METHOD,PARAMETER,TYPE}) @Retention(RUNTIME) public @interface JsonFormatGeneral-purpose annotation used for configuring details of how values of properties are to be serialized. Unlike most other Jackson annotations, annotation does not have specific universal interpretation: instead, effect depends on datatype of property being annotated (or more specifically, deserializer and serializer being used).Common uses include choosing between alternate representations -- for example, whether
Dateis to be serialized as number (Java timestamp) or String (such as ISO-8601 compatible time value) -- as well as configuring exact details withpattern()property.As of Jackson 2.6, known special handling includes:
Date: Shape can beJsonFormat.Shape.STRINGorJsonFormat.Shape.NUMBER; pattern may containSimpleDateFormat-compatible pattern definition.- Can be used on Classes (types) as well, for modified default behavior, possibly overridden by per-property annotation
Enums: ShapesJsonFormat.Shape.STRINGandJsonFormat.Shape.NUMBERcan be used to change between numeric (index) and textual (name ortoString()); but it is also possible to useJsonFormat.Shape.OBJECTto serialize (but not deserialize)Enums as JSON Objects (as if they were POJOs). NOTE: serialization as JSON Object only works with class annotation; will not work as per-property annotation.Collections can be serialized as (and deserialized from) JSON Objects, ifJsonFormat.Shape.OBJECTis used. NOTE: can ONLY be used as class annotation; will not work as per-property annotation.Numbersubclasses can be serialized as full objects ifJsonFormat.Shape.OBJECTis used. Otherwise the default behavior of serializing to a scalar number value will be preferred. NOTE: can ONLY be used as class annotation; will not work as per-property annotation.
- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Fields Description static java.lang.StringDEFAULT_LOCALEValue that indicates that defaultLocale(from deserialization or serialization context) should be used: annotation does not define value to use.static java.lang.StringDEFAULT_TIMEZONEValue that indicates that defaultTimeZone(from deserialization or serialization context) should be used: annotation does not define value to use.
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description OptBooleanlenientProperty that indicates whether "lenient" handling should be enabled or disabled.java.lang.StringlocaleLocaleto use for serialization (if needed).java.lang.StringpatternDatatype-specific additional piece of configuration that may be used to further refine formatting aspects.JsonFormat.ShapeshapeStructure to use for serialization: definition of mapping depends on datatype, but usually has straight-forward counterpart in data format (JSON).java.lang.StringtimezoneTimeZoneto use for serialization (if needed).JsonFormat.Feature[]withSet ofJsonFormat.Features to explicitly enable with respect to handling of annotated property.JsonFormat.Feature[]withoutSet ofJsonFormat.Features to explicitly disable with respect to handling of annotated property.
-
-
-
-
DEFAULT_TIMEZONE
static final java.lang.String DEFAULT_TIMEZONE
Value that indicates that defaultTimeZone(from deserialization or serialization context) should be used: annotation does not define value to use.NOTE: default here does NOT mean JVM defaults but Jackson databindings default, usually UTC, but may be changed on
ObjectMapper.
-
-
Element Detail
-
pattern
java.lang.String pattern
Datatype-specific additional piece of configuration that may be used to further refine formatting aspects. This may, for example, determine low-level format String used forDateserialization; however, exact use is determined by specificJsonSerializer- Default:
- ""
-
-
-
shape
JsonFormat.Shape shape
Structure to use for serialization: definition of mapping depends on datatype, but usually has straight-forward counterpart in data format (JSON). Note that commonly only a subset of shapes is available; and if 'invalid' value is chosen, defaults are usually used.- Default:
- com.fasterxml.jackson.annotation.JsonFormat.Shape.ANY
-
-
-
locale
java.lang.String locale
Localeto use for serialization (if needed). Special value ofDEFAULT_LOCALEcan be used to mean "just use the default", where default is specified by the serialization context, which in turn defaults to system defaults (Locale.getDefault()) unless explicitly set to another locale.- Default:
- "##default"
-
-
-
timezone
java.lang.String timezone
TimeZoneto use for serialization (if needed). Special value ofDEFAULT_TIMEZONEcan be used to mean "just use the default", where default is specified by the serialization context, which in turn defaults to system default (UTC) unless explicitly set to another timezone.- Default:
- "##default"
-
-
-
lenient
OptBoolean lenient
Property that indicates whether "lenient" handling should be enabled or disabled. This is relevant mostly for deserialization of some textual datatypes, especially date/time types.Note that underlying default setting depends on datatype (or more precisely deserializer for it): for most date/time types, default is for leniency to be enabled.
- Since:
- 2.9
- Default:
- com.fasterxml.jackson.annotation.OptBoolean.DEFAULT
-
-
-
with
JsonFormat.Feature[] with
Set ofJsonFormat.Features to explicitly enable with respect to handling of annotated property. This will have precedence over possible global configuration.- Since:
- 2.6
- Default:
- {}
-
-
-
without
JsonFormat.Feature[] without
Set ofJsonFormat.Features to explicitly disable with respect to handling of annotated property. This will have precedence over possible global configuration.- Since:
- 2.6
- Default:
- {}
-
-