@Target(value={ANNOTATION_TYPE,FIELD,METHOD,PARAMETER,TYPE}) @Retention(value=RUNTIME) public @interface JsonFormat
Common uses include choosing between alternate representations -- for example,
whether Date
is to be serialized as number (Java timestamp)
or String (such as ISO-8601 compatible time value) -- as well as configuring
exact details with pattern()
property.
As of Jackson 2.6, known special handling includes:
Date
: Shape can be JsonFormat.Shape.STRING
or JsonFormat.Shape.NUMBER
;
pattern may contain SimpleDateFormat
-compatible pattern definition.
Enum
s: Shapes JsonFormat.Shape.STRING
and JsonFormat.Shape.NUMBER
can be
used to change between numeric (index) and textual (name or toString()
);
but it is also possible to use JsonFormat.Shape.OBJECT
to serialize (but not deserialize)
Enum
s 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.
Collection
s can be serialized as (and deserialized from) JSON Objects,
if JsonFormat.Shape.OBJECT
is used. NOTE: can ONLY be used as class annotation;
will not work as per-property annotation.
Number
subclasses can be serialized as full objects if
JsonFormat.Shape.OBJECT
is 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.
Modifier and Type | Fields and Description |
---|---|
static String |
DEFAULT_LOCALE
Value that indicates that default
Locale
(from deserialization or serialization context) should be used:
annotation does not define value to use. |
static String |
DEFAULT_TIMEZONE
Value that indicates that default
TimeZone
(from deserialization or serialization context) should be used:
annotation does not define value to use. |
Modifier and Type | Optional Element and Description |
---|---|
OptBoolean |
lenient
Property that indicates whether "lenient" handling should be enabled or
disabled.
|
String |
locale
Locale to use for serialization (if needed). |
String |
pattern
Datatype-specific additional piece of configuration that may be used
to further refine formatting aspects.
|
JsonFormat.Shape |
shape
Structure to use for serialization: definition of mapping depends on datatype,
but usually has straight-forward counterpart in data format (JSON).
|
String |
timezone
TimeZone to use for serialization (if needed). |
JsonFormat.Feature[] |
with
Set of
JsonFormat.Feature s to explicitly enable with respect
to handling of annotated property. |
JsonFormat.Feature[] |
without
Set of
JsonFormat.Feature s to explicitly disable with respect
to handling of annotated property. |
public static final String DEFAULT_TIMEZONE
TimeZone
(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
.
public abstract String pattern
Date
serialization;
however, exact use is determined by specific JsonSerializer
public abstract JsonFormat.Shape shape
public abstract String locale
Locale
to use for serialization (if needed).
Special value of DEFAULT_LOCALE
can 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.public abstract String timezone
TimeZone
to use for serialization (if needed).
Special value of DEFAULT_TIMEZONE
can 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.public abstract OptBoolean lenient
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.
public abstract JsonFormat.Feature[] with
JsonFormat.Feature
s to explicitly enable with respect
to handling of annotated property. This will have precedence over possible
global configuration.public abstract JsonFormat.Feature[] without
JsonFormat.Feature
s to explicitly disable with respect
to handling of annotated property. This will have precedence over possible
global configuration.Copyright © 2008–2023 FasterXML. All rights reserved.