Class DurationSerializer
java.lang.Object
com.fasterxml.jackson.databind.JsonSerializer<Duration>
com.fasterxml.jackson.databind.ser.std.StdSerializer<Duration>
com.fasterxml.jackson.datatype.jsr310.ser.JSR310SerializerBase<Duration>
com.fasterxml.jackson.datatype.jsr310.ser.JSR310FormattedSerializerBase<Duration>
com.fasterxml.jackson.datatype.jsr310.ser.DurationSerializer
- All Implemented Interfaces:
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable
,com.fasterxml.jackson.databind.jsonschema.SchemaAware
,com.fasterxml.jackson.databind.ser.ContextualSerializer
,Serializable
Serializer for Java 8 temporal
Duration
s.
NOTE: since 2.10, SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS
determines global default used for determining if serialization should use
numeric (timestamps) or textual representation. Before this,
SerializationFeature.WRITE_DATES_AS_TIMESTAMPS
was used.
- Since:
- 2.2
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonSerializer
com.fasterxml.jackson.databind.JsonSerializer.None
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DurationUnitConverter
When defined (notnull
) duration values will be converted into integers with the unit configured for the converter.static final DurationSerializer
private static final long
Fields inherited from class com.fasterxml.jackson.datatype.jsr310.ser.JSR310FormattedSerializerBase
_formatter, _integerListType, _shape, _useNanoseconds, _useTimestamp
Fields inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer
_handledType
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
protected
DurationSerializer
(DurationSerializer base, DurationUnitConverter converter) protected
DurationSerializer
(DurationSerializer base, Boolean useTimestamp, Boolean useNanoseconds, DateTimeFormatter dtf) protected
DurationSerializer
(DurationSerializer base, Boolean useTimestamp, DateTimeFormatter dtf) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
_acceptTimestampVisitor
(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper visitor, com.fasterxml.jackson.databind.JavaType typeHint) private BigDecimal
protected DateTimeFormatter
_useDateTimeFormatter
(com.fasterxml.jackson.databind.SerializerProvider prov, com.fasterxml.jackson.annotation.JsonFormat.Value format) com.fasterxml.jackson.databind.JsonSerializer
<?> createContextual
(com.fasterxml.jackson.databind.SerializerProvider prov, com.fasterxml.jackson.databind.BeanProperty property) protected com.fasterxml.jackson.databind.SerializationFeature
Overridable method that determinesSerializationFeature
that is used as the global default in determining if date/time value serialized should use numeric format ("timestamp") or not.protected com.fasterxml.jackson.core.JsonToken
serializationShape
(com.fasterxml.jackson.databind.SerializerProvider provider) Overridable helper method used fromJSR310SerializerBase.serializeWithType(T, com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.SerializerProvider, com.fasterxml.jackson.databind.jsontype.TypeSerializer)
, to indicate shape of value during serialization; needed to know how type id is to be serialized.void
serialize
(Duration duration, com.fasterxml.jackson.core.JsonGenerator generator, com.fasterxml.jackson.databind.SerializerProvider provider) protected DurationSerializer
withConverter
(DurationUnitConverter converter) protected JSR310FormattedSerializerBase
<?> withFeatures
(Boolean writeZoneId, Boolean writeNanoseconds) protected DurationSerializer
withFormat
(Boolean useTimestamp, DateTimeFormatter dtf, com.fasterxml.jackson.annotation.JsonFormat.Shape shape) Methods inherited from class com.fasterxml.jackson.datatype.jsr310.ser.JSR310FormattedSerializerBase
_integerListType, _useTimestampExplicitOnly, acceptJsonFormatVisitor, getSchema, useNanoseconds, useTimestamp, withFeatures
Methods inherited from class com.fasterxml.jackson.datatype.jsr310.ser.JSR310SerializerBase
serializeWithType
Methods inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer
_neitherNull, _nonEmpty, createSchemaNode, createSchemaNode, findAnnotatedContentSerializer, findContextualConvertingSerializer, findConvertingContentSerializer, findFormatFeature, findFormatOverrides, findIncludeOverrides, findPropertyFilter, getSchema, handledType, isDefaultSerializer, visitArrayFormat, visitArrayFormat, visitFloatFormat, visitIntFormat, visitIntFormat, visitStringFormat, visitStringFormat, wrapAndThrow, wrapAndThrow
Methods inherited from class com.fasterxml.jackson.databind.JsonSerializer
getDelegatee, isEmpty, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, unwrappingSerializer, usesObjectId, withFilterId, withIgnoredProperties
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
INSTANCE
-
_durationUnitConverter
When defined (notnull
) duration values will be converted into integers with the unit configured for the converter. Only available whenSerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS
is enabled andSerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS
is not enabled since the duration converters do not support fractions- Since:
- 2.12
-
-
Constructor Details
-
DurationSerializer
protected DurationSerializer() -
DurationSerializer
-
DurationSerializer
protected DurationSerializer(DurationSerializer base, Boolean useTimestamp, Boolean useNanoseconds, DateTimeFormatter dtf) -
DurationSerializer
-
-
Method Details
-
withFormat
protected DurationSerializer withFormat(Boolean useTimestamp, DateTimeFormatter dtf, com.fasterxml.jackson.annotation.JsonFormat.Shape shape) - Specified by:
withFormat
in classJSR310FormattedSerializerBase<Duration>
-
withConverter
-
getTimestampsFeature
protected com.fasterxml.jackson.databind.SerializationFeature getTimestampsFeature()Description copied from class:JSR310FormattedSerializerBase
Overridable method that determinesSerializationFeature
that 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:
getTimestampsFeature
in classJSR310FormattedSerializerBase<Duration>
-
createContextual
public com.fasterxml.jackson.databind.JsonSerializer<?> createContextual(com.fasterxml.jackson.databind.SerializerProvider prov, com.fasterxml.jackson.databind.BeanProperty property) throws com.fasterxml.jackson.databind.JsonMappingException - Specified by:
createContextual
in interfacecom.fasterxml.jackson.databind.ser.ContextualSerializer
- Overrides:
createContextual
in classJSR310FormattedSerializerBase<Duration>
- Throws:
com.fasterxml.jackson.databind.JsonMappingException
-
serialize
public void serialize(Duration duration, com.fasterxml.jackson.core.JsonGenerator generator, com.fasterxml.jackson.databind.SerializerProvider provider) throws IOException - Specified by:
serialize
in classcom.fasterxml.jackson.databind.ser.std.StdSerializer<Duration>
- Throws:
IOException
-
_toNanos
-
_acceptTimestampVisitor
protected void _acceptTimestampVisitor(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper visitor, com.fasterxml.jackson.databind.JavaType typeHint) throws com.fasterxml.jackson.databind.JsonMappingException - Overrides:
_acceptTimestampVisitor
in classJSR310FormattedSerializerBase<Duration>
- Throws:
com.fasterxml.jackson.databind.JsonMappingException
-
serializationShape
protected com.fasterxml.jackson.core.JsonToken serializationShape(com.fasterxml.jackson.databind.SerializerProvider provider) Description copied from class:JSR310SerializerBase
Overridable helper method used fromJSR310SerializerBase.serializeWithType(T, com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.SerializerProvider, com.fasterxml.jackson.databind.jsontype.TypeSerializer)
, to indicate shape of value during serialization; needed to know how type id is to be serialized.- Specified by:
serializationShape
in classJSR310SerializerBase<Duration>
-
withFeatures
protected JSR310FormattedSerializerBase<?> withFeatures(Boolean writeZoneId, Boolean writeNanoseconds) - Overrides:
withFeatures
in classJSR310FormattedSerializerBase<Duration>
-
_useDateTimeFormatter
protected DateTimeFormatter _useDateTimeFormatter(com.fasterxml.jackson.databind.SerializerProvider prov, com.fasterxml.jackson.annotation.JsonFormat.Value format) - Overrides:
_useDateTimeFormatter
in classJSR310FormattedSerializerBase<Duration>
-