Class AbstractDateTimeSerializer<T>
- java.lang.Object
-
- org.eclipse.yasson.internal.serializer.AbstractValueTypeSerializer<T>
-
- org.eclipse.yasson.internal.serializer.AbstractDateTimeSerializer<T>
-
- Type Parameters:
T
- Type to serialize.
- All Implemented Interfaces:
javax.json.bind.serializer.JsonbSerializer<T>
- Direct Known Subclasses:
AbstractDateTypeSerializer
,CalendarTypeSerializer
,InstantTypeSerializer
,LocalDateTimeTypeSerializer
,LocalDateTypeSerializer
,LocalTimeTypeSerializer
,OffsetDateTimeTypeSerializer
,OffsetTimeTypeSerializer
,XMLGregorianCalendarTypeSerializer
,ZonedDateTimeTypeSerializer
public abstract class AbstractDateTimeSerializer<T> extends AbstractValueTypeSerializer<T>
Abstract class for converting date objects.- Author:
- Roman Grigoriadi
-
-
Field Summary
Fields Modifier and Type Field Description static ZoneId
UTC
-
Fields inherited from class org.eclipse.yasson.internal.serializer.AbstractValueTypeSerializer
customization
-
-
Constructor Summary
Constructors Constructor Description AbstractDateTimeSerializer(Customization customization)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract String
formatDefault(T value, Locale locale)
Format with default formatter for a givenjava.time
date object.protected String
formatStrictIJson(T value)
Format date object as strict IJson date format.protected String
formatWithFormatter(T value, DateTimeFormatter formatter)
Format date object with given formatterprotected JsonbDateFormatter
getJsonbDateFormatter(JsonbContext context)
protected DateTimeFormatter
getZonedFormatter(DateTimeFormatter formatter)
Append UTC zone in case zone is not set on formatter.void
serialize(T obj, javax.json.stream.JsonGenerator generator, javax.json.bind.serializer.SerializationContext ctx)
Serializes an object to JSON.protected void
serialize(T obj, javax.json.stream.JsonGenerator generator, Marshaller marshaller)
protected abstract Instant
toInstant(T value)
Convert java.time object to epoch milliseconds instant.String
toJson(T object, JsonbDateFormatter formatter, JsonbContext jsonbContext)
Converts to JSON string.protected TemporalAccessor
toTemporalAccessor(T object)
Convert date object toTemporalAccessor
Only for legacy dates.
-
-
-
Field Detail
-
UTC
public static final ZoneId UTC
-
-
Constructor Detail
-
AbstractDateTimeSerializer
public AbstractDateTimeSerializer(Customization customization)
Creates a new instance.- Parameters:
customization
- Model customization.
-
-
Method Detail
-
serialize
public void serialize(T obj, javax.json.stream.JsonGenerator generator, javax.json.bind.serializer.SerializationContext ctx)
Description copied from class:AbstractValueTypeSerializer
Serializes an object to JSON.- Specified by:
serialize
in interfacejavax.json.bind.serializer.JsonbSerializer<T>
- Overrides:
serialize
in classAbstractValueTypeSerializer<T>
- Parameters:
obj
- Object to serialize.generator
- JSON generator to use.ctx
- JSON-B mapper context.
-
toJson
public String toJson(T object, JsonbDateFormatter formatter, JsonbContext jsonbContext)
Converts to JSON string.- Parameters:
object
- Object to convert.formatter
- Formatter to use.jsonbContext
- JSON-B context.- Returns:
- JSON representation of given object.
-
getJsonbDateFormatter
protected JsonbDateFormatter getJsonbDateFormatter(JsonbContext context)
-
getZonedFormatter
protected DateTimeFormatter getZonedFormatter(DateTimeFormatter formatter)
Append UTC zone in case zone is not set on formatter.- Parameters:
formatter
- formatter- Returns:
- zoned formatter
-
toTemporalAccessor
protected TemporalAccessor toTemporalAccessor(T object)
Convert date object toTemporalAccessor
Only for legacy dates.- Parameters:
object
- date object- Returns:
- converted
TemporalAccessor
-
toInstant
protected abstract Instant toInstant(T value)
Convert java.time object to epoch milliseconds instant. Discards zone offset and zone id information.- Parameters:
value
- date object to convert- Returns:
- instant
-
formatDefault
protected abstract String formatDefault(T value, Locale locale)
Format with default formatter for a givenjava.time
date object. Different default formatter for each date object type is used.- Parameters:
value
- date objectlocale
- locale from annotation / default not null- Returns:
- formatted date obj as string
-
formatWithFormatter
protected String formatWithFormatter(T value, DateTimeFormatter formatter)
Format date object with given formatter- Parameters:
value
- date object to formatformatter
- formatter to format with- Returns:
- formatted result
-
formatStrictIJson
protected String formatStrictIJson(T value)
Format date object as strict IJson date format.- Parameters:
value
- value to format- Returns:
- formatted result
-
serialize
protected void serialize(T obj, javax.json.stream.JsonGenerator generator, Marshaller marshaller)
- Specified by:
serialize
in classAbstractValueTypeSerializer<T>
-
-