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,SqlTimestampTypeSerializer,XMLGregorianCalendarTypeSerializer,ZonedDateTimeTypeSerializer
public abstract class AbstractDateTimeSerializer<T> extends AbstractValueTypeSerializer<T>
Abstract class for converting date objects.
-
-
Field Summary
Fields Modifier and Type Field Description static java.time.ZoneIdUTCDefault zone id.
-
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 java.lang.StringformatDefault(T value, java.util.Locale locale)Format with default formatter for a given java.time date object.protected java.lang.StringformatStrictIJson(T value)Format date object as strict IJson date format.protected java.lang.StringformatWithFormatter(T value, java.time.format.DateTimeFormatter formatter)Format date object with given formatter.protected JsonbDateFormattergetJsonbDateFormatter(JsonbContext context)Returns registered serialization jsonb date formatter.protected java.time.format.DateTimeFormattergetZonedFormatter(java.time.format.DateTimeFormatter formatter)Append UTC zone in case zone is not set on formatter.voidserialize(T obj, javax.json.stream.JsonGenerator generator, javax.json.bind.serializer.SerializationContext ctx)Serializes an object to JSON.protected voidserialize(T obj, javax.json.stream.JsonGenerator generator, Marshaller marshaller)Serializes an object to JSON.protected abstract java.time.InstanttoInstant(T value)Convert java.time object to epoch milliseconds instant.java.lang.StringtoJson(T object, JsonbDateFormatter formatter, JsonbContext jsonbContext)Converts to JSON string.protected java.time.temporal.TemporalAccessortoTemporalAccessor(T object)Convert date object toTemporalAccessorOnly for legacy dates.-
Methods inherited from class org.eclipse.yasson.internal.serializer.AbstractValueTypeSerializer
getCustomization
-
-
-
-
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:AbstractValueTypeSerializerSerializes an object to JSON.- Specified by:
serializein interfacejavax.json.bind.serializer.JsonbSerializer<T>- Overrides:
serializein classAbstractValueTypeSerializer<T>- Parameters:
obj- Object to serialize.generator- JSON generator to use.ctx- JSON-B mapper context.
-
toJson
public java.lang.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)
Returns registered serialization jsonb date formatter.- Parameters:
context- context- Returns:
- jsonb formatter
-
getZonedFormatter
protected java.time.format.DateTimeFormatter getZonedFormatter(java.time.format.DateTimeFormatter formatter)
Append UTC zone in case zone is not set on formatter.- Parameters:
formatter- formatter- Returns:
- zoned formatter
-
toTemporalAccessor
protected java.time.temporal.TemporalAccessor toTemporalAccessor(T object)
Convert date object toTemporalAccessorOnly for legacy dates.- Parameters:
object- date object- Returns:
- converted
TemporalAccessor
-
toInstant
protected abstract java.time.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 java.lang.String formatDefault(T value, java.util.Locale locale)
Format with default formatter for a given java.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 java.lang.String formatWithFormatter(T value, java.time.format.DateTimeFormatter formatter)
Format date object with given formatter.- Parameters:
value- date object to formatformatter- formatter to format with- Returns:
- formatted result
-
formatStrictIJson
protected java.lang.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)
Description copied from class:AbstractValueTypeSerializerSerializes an object to JSON.- Specified by:
serializein classAbstractValueTypeSerializer<T>- Parameters:
obj- Object to serialize.generator- JSON generator to use.marshaller- Marshaller.
-
-