Class DurationSerializer
java.lang.Object
tools.jackson.databind.ValueSerializer<Duration>
tools.jackson.databind.ser.std.StdSerializer<Duration>
tools.jackson.databind.ext.javatime.ser.JSR310SerializerBase<Duration>
tools.jackson.databind.ext.javatime.ser.JSR310FormattedSerializerBase<Duration>
tools.jackson.databind.ext.javatime.ser.DurationSerializer
- All Implemented Interfaces:
JsonFormatVisitable
Serializer for Java 8 temporal
Durations.
NOTE: since 2.10, DateTimeFeature.WRITE_DURATIONS_AS_TIMESTAMPS
determines global default used for determining if serialization should use
numeric (timestamps) or textual representation. Before this,
DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS was used.
-
Nested Class Summary
Nested classes/interfaces inherited from class ValueSerializer
ValueSerializer.None -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DurationUnitConverterWhen defined (notnull) duration values will be converted into integers with the unit configured for the converter.static final DurationSerializerFields inherited from class JSR310FormattedSerializerBase
_formatter, _integerListType, _shape, _useNanoseconds, _useTimestampFields inherited from class StdSerializer
_handledType -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedDurationSerializer(DurationSerializer base, DateTimeFormatter dtf, Boolean useTimestamp) protectedDurationSerializer(DurationSerializer base, DateTimeFormatter dtf, Boolean useTimestamp, Boolean useNanoseconds) protectedDurationSerializer(DurationSerializer base, DurationUnitConverter converter) -
Method Summary
Modifier and TypeMethodDescriptionprotected void_acceptTimestampVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) private BigDecimalprotected DateTimeFormatter_useDateTimeFormatter(SerializationContext ctxt, com.fasterxml.jackson.annotation.JsonFormat.Value format) createContextual(SerializationContext ctxt, BeanProperty property) Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property (or, for root values, in which case `null` is passed).protected DateTimeFeatureOverridable method that determinesSerializationFeaturethat is used as the global default in determining if date/time value serialized should use numeric format ("timestamp") or not.protected tools.jackson.core.JsonTokenOverridable helper method used fromJSR310SerializerBase.serializeWithType(T, JsonGenerator, SerializationContext, TypeSerializer), to indicate shape of value during serialization; needed to know how type id is to be serialized.voidserialize(Duration duration, tools.jackson.core.JsonGenerator generator, SerializationContext ctxt) Method that can be called to ask implementation to serialize values of type this serializer handles.protected DurationSerializerwithConverter(DurationUnitConverter converter) protected JSR310FormattedSerializerBase<?> withFeatures(Boolean writeZoneId, Boolean writeNanoseconds) protected DurationSerializerwithFormat(DateTimeFormatter dtf, Boolean useTimestamp, com.fasterxml.jackson.annotation.JsonFormat.Shape shape) Methods inherited from class JSR310FormattedSerializerBase
_integerListType, _useTimestampExplicitOnly, acceptJsonFormatVisitor, useNanoseconds, useTimestamp, useTimestampFromGlobalDefaultsMethods inherited from class JSR310SerializerBase
serializeWithTypeMethods inherited from class StdSerializer
_neitherNull, _nonEmpty, _wrapIOFailure, acceptJsonFormatVisitorForBinary, createSchemaNode, createSchemaNode, findAnnotatedContentSerializer, findContextualConvertingSerializer, findFormatFeature, findFormatOverrides, findIncludeOverrides, findPropertyFilter, handledType, isDefaultSerializer, visitArrayFormat, visitArrayFormat, visitFloatFormat, visitIntFormat, visitIntFormat, visitStringFormat, visitStringFormat, wrapAndThrow, wrapAndThrowMethods inherited from class ValueSerializer
getDelegatee, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, resolve, unwrappingSerializer, usesObjectId, withFilterId, withFormatOverrides, withIgnoredProperties
-
Field Details
-
INSTANCE
-
_durationUnitConverter
When defined (notnull) duration values will be converted into integers with the unit configured for the converter. Only available whenis enabled andinvalid reference
SerializationFeature#WRITE_DURATIONS_AS_TIMESTAMPSis not enabled since the duration converters do not support fractionsinvalid reference
SerializationFeature#WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS
-
-
Constructor Details
-
DurationSerializer
protected DurationSerializer() -
DurationSerializer
-
DurationSerializer
protected DurationSerializer(DurationSerializer base, DateTimeFormatter dtf, Boolean useTimestamp, Boolean useNanoseconds) -
DurationSerializer
-
-
Method Details
-
withFormat
protected DurationSerializer withFormat(DateTimeFormatter dtf, Boolean useTimestamp, com.fasterxml.jackson.annotation.JsonFormat.Shape shape) - Specified by:
withFormatin classJSR310FormattedSerializerBase<Duration>
-
withConverter
-
getTimestampsFeature
Description copied from class:JSR310FormattedSerializerBaseOverridable method that determinesSerializationFeaturethat is used as the global default in determining if date/time value serialized should use numeric format ("timestamp") or not.Note that this feature is just the baseline setting and may be overridden on per-type or per-property basis.
- Overrides:
getTimestampsFeaturein classJSR310FormattedSerializerBase<Duration>
-
createContextual
Description copied from class:ValueSerializerMethod called to see if a different (or differently configured) serializer is needed to serialize values of specified property (or, for root values, in which case `null` is passed). Note that instance that this method is called on is typically shared one and as a result method should NOT modify this instance but rather construct and return a new instance. This instance should only be returned as-is, in case it is already suitable for use.Note that method is only called once per POJO property, and for the first usage as root value serializer; it is not called for every serialization, as doing that would have significant performance impact; most serializers cache contextual instances for future use.
- Overrides:
createContextualin classJSR310FormattedSerializerBase<Duration>- Parameters:
ctxt- Context to use for accessing config, other serializersproperty- Property (defined by one or more accessors - field or method - used for accessing logical property value) for which serializer is used to be used; or, `null` for root value (or in cases where caller does not have this information, which is handled as root value case).- Returns:
- Serializer to use for serializing values of specified property; may be this instance or a new instance.
-
serialize
public void serialize(Duration duration, tools.jackson.core.JsonGenerator generator, SerializationContext ctxt) throws tools.jackson.core.JacksonException Description copied from class:ValueSerializerMethod that can be called to ask implementation to serialize values of type this serializer handles.- Specified by:
serializein classStdSerializer<Duration>- Parameters:
duration- Value to serialize; can not be null.generator- Generator used to output resulting Json contentctxt- Context that can be used to get serializers for serializing Objects value contains, if any.- Throws:
tools.jackson.core.JacksonException
-
_toNanos
-
_acceptTimestampVisitor
- Overrides:
_acceptTimestampVisitorin classJSR310FormattedSerializerBase<Duration>
-
serializationShape
Description copied from class:JSR310SerializerBaseOverridable helper method used fromJSR310SerializerBase.serializeWithType(T, JsonGenerator, SerializationContext, TypeSerializer), to indicate shape of value during serialization; needed to know how type id is to be serialized.- Specified by:
serializationShapein classJSR310SerializerBase<Duration>
-
withFeatures
protected JSR310FormattedSerializerBase<?> withFeatures(Boolean writeZoneId, Boolean writeNanoseconds) - Overrides:
withFeaturesin classJSR310FormattedSerializerBase<Duration>
-
_useDateTimeFormatter
protected DateTimeFormatter _useDateTimeFormatter(SerializationContext ctxt, com.fasterxml.jackson.annotation.JsonFormat.Value format) - Overrides:
_useDateTimeFormatterin classJSR310FormattedSerializerBase<Duration>
-