Class DefaultFormattedTemporalSerde<T extends TemporalAccessor>
java.lang.Object
io.micronaut.serde.support.serdes.DefaultFormattedTemporalSerde<T>
- Type Parameters:
T- The temporal type
- All Implemented Interfaces:
Deserializer<T>, FormattedDeserializer<T>, FormattedSerde<T>, FormattedSerializer<T>, Serde<T>, Serializer<T>, TemporalSerde<T>
- Direct Known Subclasses:
InstantSerde, LocalDateSerde, LocalDateTimeSerde, LocalTimeSerde, OffsetDateTimeSerde, ZonedDateTimeSerde
public abstract sealed class DefaultFormattedTemporalSerde<T extends TemporalAccessor>
extends Object
implements TemporalSerde<T>
permits LocalDateSerde, LocalDateTimeSerde (not exhaustive)
Super class that can be used for the default date/time formatting.
- Author:
- gkrocher
-
Nested Class Summary
Nested classes/interfaces inherited from interface Deserializer
Deserializer.DecoderContextNested classes/interfaces inherited from interface Serializer
Serializer.EncoderContext -
Field Summary
Fields inherited from interface TemporalSerde
UTC -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefaultFormattedTemporalSerde(DateTimeFormatter stringFormatter) -
Method Summary
Modifier and TypeMethodDescriptionprotected static Optional<DateTimeFormatter> createFormatter(SerdeConfiguration configuration) protected DefaultFormattedTemporalSerde<T> createSpecific(SerdeConfiguration configuration) Create the same serde with new configuration.createSpecific(Deserializer.DecoderContext decoderContext, io.micronaut.core.type.Argument<? super T> context) Create a new child deserializer or return this if non is necessary for the given context.createSpecific(Deserializer.DecoderContext decoderContext, io.micronaut.core.type.Argument<? super T> type, FormatConfiguration format) Create a more specific deserializer for the given definition and format configuration.createSpecific(Serializer.EncoderContext context, io.micronaut.core.type.Argument<? extends T> type) Create a more specific serializer for the given definition.createSpecific(Serializer.EncoderContext context, io.micronaut.core.type.Argument<? extends T> type, FormatConfiguration format) Create a more specific serializer for the given definition and format configuration.protected DefaultFormattedTemporalSerde<T> createSpecific(DateTimeFormatter stringFormatter, SerdeConfiguration.TimeShape timeWriteShape, SerdeConfiguration.NumericTimeUnit numericUnit) Create the same serde with a new string formatter and explicit shape-derived values.protected DefaultFormattedTemporalSerde<T> createSpecific(DateTimeFormatter stringFormatter, SerdeConfiguration.TimeShape timeWriteShape, SerdeConfiguration.NumericTimeUnit numericUnit, FormatConfiguration format) Create the same serde with a new string formatter and explicit format-derived values.protected DefaultFormattedTemporalSerde<T> createSpecificForDeserialization(DateTimeFormatter stringFormatter, SerdeConfiguration.TimeShape timeWriteShape, SerdeConfiguration.NumericTimeUnit numericUnit, SerdeConfiguration configuration, Set<DeserializationConfiguration.Feature> features) Create the same serde with deserialization configuration-derived values.protected DefaultFormattedTemporalSerde<T> createSpecificForDeserialization(DateTimeFormatter stringFormatter, SerdeConfiguration.TimeShape timeWriteShape, SerdeConfiguration.NumericTimeUnit numericUnit, FormatConfiguration format, Set<DeserializationConfiguration.Feature> features) Create the same serde with deserialization format-derived values.protected DefaultFormattedTemporalSerde<T> createSpecificForSerialization(DateTimeFormatter stringFormatter, SerdeConfiguration.TimeShape timeWriteShape, SerdeConfiguration.NumericTimeUnit numericUnit, FormatConfiguration format, Set<SerializationConfiguration.Feature> features) Create the same serde with serialization format-derived values.protected DateTimeFormatterprotected DateTimeFormatterprotected DateTimeFormatterdefaultStringFormatter(FormatConfiguration format, Set<SerializationConfiguration.Feature> features) final Tdeserialize(Decoder decoder, Deserializer.DecoderContext decoderContext, io.micronaut.core.type.Argument<? super T> type) final voidserialize(Encoder encoder, Serializer.EncoderContext context, io.micronaut.core.type.Argument<? extends T> type, T value) Serializes the given value using the passedEncoder.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Deserializer
deserializeNullable, getDefaultValueMethods inherited from interface Serializer
isAbsent, isDefault, isEmptyMethods inherited from interface TemporalSerde
query
-
Constructor Details
-
DefaultFormattedTemporalSerde
- Parameters:
stringFormatter- The resolved string formatter
-
-
Method Details
-
createFormatter
-
createSpecific
public Serializer<T> createSpecific(Serializer.EncoderContext context, io.micronaut.core.type.Argument<? extends T> type) Description copied from interface:SerializerCreate a more specific serializer for the given definition.- Specified by:
createSpecificin interfaceSerializer<T extends TemporalAccessor>- Specified by:
createSpecificin interfaceTemporalSerde<T extends TemporalAccessor>- Parameters:
context- The encoder contexttype- The type definition including any annotation metadata- Returns:
- The more specific serializer
-
createSpecific
public Serializer<T> createSpecific(Serializer.EncoderContext context, io.micronaut.core.type.Argument<? extends T> type, FormatConfiguration format) Description copied from interface:FormattedSerializerCreate a more specific serializer for the given definition and format configuration.- Specified by:
createSpecificin interfaceFormattedSerializer<T extends TemporalAccessor>- Specified by:
createSpecificin interfaceTemporalSerde<T extends TemporalAccessor>- Parameters:
context- The encoder contexttype- The type definition including any annotation metadataformat- The format configuration- Returns:
- The more specific serializer
-
createSpecific
public Deserializer<T> createSpecific(Deserializer.DecoderContext decoderContext, io.micronaut.core.type.Argument<? super T> context) throws SerdeException Description copied from interface:DeserializerCreate a new child deserializer or return this if non is necessary for the given context.- Specified by:
createSpecificin interfaceDeserializer<T extends TemporalAccessor>- Specified by:
createSpecificin interfaceTemporalSerde<T extends TemporalAccessor>- Parameters:
decoderContext- The decoder contextcontext- The context, including any annotation metadata and type information to narrow the deserializer type- Returns:
- An instance of the same type of deserializer
- Throws:
SerdeException
-
createSpecific
public Deserializer<T> createSpecific(Deserializer.DecoderContext decoderContext, io.micronaut.core.type.Argument<? super T> type, FormatConfiguration format) throws SerdeException Description copied from interface:FormattedDeserializerCreate a more specific deserializer for the given definition and format configuration.- Specified by:
createSpecificin interfaceFormattedDeserializer<T extends TemporalAccessor>- Specified by:
createSpecificin interfaceTemporalSerde<T extends TemporalAccessor>- Parameters:
decoderContext- The decoder contexttype- The type definition including any annotation metadataformat- The format configuration- Returns:
- The more specific deserializer
- Throws:
SerdeException- If the deserializer cannot be selected
-
createSpecific
Create the same serde with new configuration.- Parameters:
configuration- The new configuration- Returns:
- The updated serde
-
createSpecific
protected DefaultFormattedTemporalSerde<T> createSpecific(DateTimeFormatter stringFormatter, SerdeConfiguration.TimeShape timeWriteShape, SerdeConfiguration.NumericTimeUnit numericUnit) Create the same serde with a new string formatter and explicit shape-derived values.- Parameters:
stringFormatter- The resolved string formattertimeWriteShape- The time write shapenumericUnit- The numeric time unit- Returns:
- The updated serde
-
createSpecific
protected DefaultFormattedTemporalSerde<T> createSpecific(DateTimeFormatter stringFormatter, SerdeConfiguration.TimeShape timeWriteShape, SerdeConfiguration.NumericTimeUnit numericUnit, FormatConfiguration format) Create the same serde with a new string formatter and explicit format-derived values.- Parameters:
stringFormatter- The resolved string formattertimeWriteShape- The time write shapenumericUnit- The numeric time unitformat- The format configuration- Returns:
- The updated serde
-
createSpecificForSerialization
protected DefaultFormattedTemporalSerde<T> createSpecificForSerialization(DateTimeFormatter stringFormatter, SerdeConfiguration.TimeShape timeWriteShape, SerdeConfiguration.NumericTimeUnit numericUnit, FormatConfiguration format, Set<SerializationConfiguration.Feature> features) Create the same serde with serialization format-derived values.- Parameters:
stringFormatter- The resolved string formattertimeWriteShape- The time write shapenumericUnit- The numeric time unitformat- The format configurationfeatures- The active serialization features- Returns:
- The updated serde
-
createSpecificForDeserialization
protected DefaultFormattedTemporalSerde<T> createSpecificForDeserialization(DateTimeFormatter stringFormatter, SerdeConfiguration.TimeShape timeWriteShape, SerdeConfiguration.NumericTimeUnit numericUnit, FormatConfiguration format, Set<DeserializationConfiguration.Feature> features) Create the same serde with deserialization format-derived values.- Parameters:
stringFormatter- The resolved string formattertimeWriteShape- The time write shapenumericUnit- The numeric time unitformat- The format configurationfeatures- The active deserialization features- Returns:
- The updated serde
-
createSpecificForDeserialization
protected DefaultFormattedTemporalSerde<T> createSpecificForDeserialization(DateTimeFormatter stringFormatter, SerdeConfiguration.TimeShape timeWriteShape, SerdeConfiguration.NumericTimeUnit numericUnit, SerdeConfiguration configuration, Set<DeserializationConfiguration.Feature> features) Create the same serde with deserialization configuration-derived values.- Parameters:
stringFormatter- The resolved string formattertimeWriteShape- The time write shapenumericUnit- The numeric time unitconfiguration- The serde configurationfeatures- The active deserialization features- Returns:
- The updated serde
-
serialize
public final void serialize(Encoder encoder, Serializer.EncoderContext context, io.micronaut.core.type.Argument<? extends T> type, T value) throws IOException Description copied from interface:SerializerSerializes the given value using the passedEncoder.- Specified by:
serializein interfaceSerializer<T extends TemporalAccessor>- Parameters:
encoder- The encoder to usecontext- The encoder context, nevernulltype- Models the generic type of the valuevalue- The value to serialize, nevernull. Callers should encode null values directly.- Throws:
IOException- If an error occurs during serialization
-
deserialize
public final T deserialize(Decoder decoder, Deserializer.DecoderContext decoderContext, io.micronaut.core.type.Argument<? super T> type) throws IOException Description copied from interface:Deserializer- Specified by:
deserializein interfaceDeserializer<T extends TemporalAccessor>- Parameters:
decoder- The decoder, nevernulldecoderContext- The decoder context, nevernulltype- The generic type to be deserialized- Returns:
- The deserialized object, never
null. UseDeserializer.deserializeNullable(Decoder, DecoderContext, Argument)when the decoder value can benull. - Throws:
IOException- If an error occurs during deserialization of the object
-
defaultStringFormatter
- Returns:
- The default formatter to use when configuration doesn't define one.
-
defaultStringFormatter
- Parameters:
format- The format configuration- Returns:
- The default formatter to use for this format when configuration doesn't define one.
-
defaultStringFormatter
protected DateTimeFormatter defaultStringFormatter(FormatConfiguration format, Set<SerializationConfiguration.Feature> features) - Parameters:
format- The format configurationfeatures- The active serialization features- Returns:
- The default formatter to use for this format when configuration doesn't define one.
-