Top Description Fields Constructors Methods
tools.jackson.databind.ext.javatime.ser

public Class DurationSerializer

extends JSR310FormattedSerializerBase<Duration>
Class Inheritance
Imports
java.math.BigDecimal, java.time.Duration, java.time.format.DateTimeFormatter, com.fasterxml.jackson.annotation.JsonFormat, tools.jackson.core.JacksonException, .JsonGenerator, .JsonParser, .JsonToken, tools.jackson.databind.*, tools.jackson.databind.cfg.DateTimeFeature, tools.jackson.databind.ext.javatime.util.DecimalUtils, .DurationUnitConverter, tools.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper, .JsonIntegerFormatVisitor, .JsonValueFormat

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.

Author
Nick Williams

Field Summary

Modifier and TypeField and Description
private DurationUnitConverter
_durationUnitConverter

When defined (not null) duration values will be converted into integers with the unit configured for the converter.

public static final DurationSerializer
Inherited from tools.jackson.databind.ext.javatime.ser.JSR310FormattedSerializerBase:
_formatter_integerListType_shape_useNanoseconds_useTimestamp

Constructor Summary

AccessConstructor and Description
protected
protected
protected
DurationSerializer(DurationSerializer base, DateTimeFormatter dtf, Boolean useTimestamp, Boolean useNanoseconds)

protected

Method Summary

Modifier and TypeMethod and Description
protected void
private BigDecimal
_toNanos(Duration duration)

protected DateTimeFormatter
public ValueSerializer<?>
createContextual(SerializationContext ctxt, BeanProperty property)

Overrides tools.jackson.databind.ext.javatime.ser.JSR310FormattedSerializerBase.createContextual.

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 DateTimeFeature
getTimestampsFeature()

Overrides tools.jackson.databind.ext.javatime.ser.JSR310FormattedSerializerBase.getTimestampsFeature.

Overridable method that determines SerializationFeature that is used as the global default in determining if date/time value serialized should use numeric format ("timestamp") or not.

protected JsonToken
serializationShape(SerializationContext ctxt)

Implements abstract tools.jackson.databind.ext.javatime.ser.JSR310SerializerBase.serializationShape.

Overridable helper method used from serializeWithType, to indicate shape of value during serialization; needed to know how type id is to be serialized.

public void
serialize(Duration duration, JsonGenerator generator, SerializationContext ctxt)

Implements abstract tools.jackson.databind.ser.std.StdSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

protected DurationSerializer
protected JSR310FormattedSerializerBase<?>
protected DurationSerializer
Inherited from tools.jackson.databind.ext.javatime.ser.JSR310FormattedSerializerBase:
_integerListType_useTimestampExplicitOnlyacceptJsonFormatVisitoruseNanosecondsuseTimestampuseTimestampFromGlobalDefaults

Field Detail

_durationUnitConverterback to summary
private DurationUnitConverter _durationUnitConverter

When defined (not null) duration values will be converted into integers with the unit configured for the converter. Only available when SerializationFeature#WRITE_DURATIONS_AS_TIMESTAMPS is enabled and SerializationFeature#WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS is not enabled since the duration converters do not support fractions

Since
2.12
INSTANCEback to summary
public static final DurationSerializer INSTANCE

Constructor Detail

DurationSerializerback to summary
protected DurationSerializer()
DurationSerializerback to summary
protected DurationSerializer(DurationSerializer base, DateTimeFormatter dtf, Boolean useTimestamp)
DurationSerializerback to summary
protected DurationSerializer(DurationSerializer base, DateTimeFormatter dtf, Boolean useTimestamp, Boolean useNanoseconds)
DurationSerializerback to summary
protected DurationSerializer(DurationSerializer base, DurationUnitConverter converter)

Method Detail

_acceptTimestampVisitorback to summary
protected void _acceptTimestampVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)

Overrides tools.jackson.databind.ext.javatime.ser.JSR310FormattedSerializerBase._acceptTimestampVisitor.

Annotations
@Override
_toNanosback to summary
private BigDecimal _toNanos(Duration duration)
_useDateTimeFormatterback to summary
protected DateTimeFormatter _useDateTimeFormatter(SerializationContext ctxt, JsonFormat.Value format)

Overrides tools.jackson.databind.ext.javatime.ser.JSR310FormattedSerializerBase._useDateTimeFormatter.

Annotations
@Override
createContextualback to summary
public ValueSerializer<?> createContextual(SerializationContext ctxt, BeanProperty property)

Overrides tools.jackson.databind.ext.javatime.ser.JSR310FormattedSerializerBase.createContextual.

Doc from tools.jackson.databind.ValueSerializer.createContextual.

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). 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.

Annotations
@Override
getTimestampsFeatureback to summary
protected DateTimeFeature getTimestampsFeature()

Overrides tools.jackson.databind.ext.javatime.ser.JSR310FormattedSerializerBase.getTimestampsFeature.

Doc from tools.jackson.databind.ext.javatime.ser.JSR310FormattedSerializerBase.getTimestampsFeature.

Overridable method that determines SerializationFeature 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.

Annotations
@Override
serializationShapeback to summary
protected JsonToken serializationShape(SerializationContext ctxt)

Implements abstract tools.jackson.databind.ext.javatime.ser.JSR310SerializerBase.serializationShape.

Doc from tools.jackson.databind.ext.javatime.ser.JSR310SerializerBase.serializationShape.

Overridable helper method used from serializeWithType, to indicate shape of value during serialization; needed to know how type id is to be serialized.

Annotations
@Override
serializeback to summary
public void serialize(Duration duration, JsonGenerator generator, SerializationContext ctxt) throws JacksonException

Implements abstract tools.jackson.databind.ser.std.StdSerializer.serialize.

Doc from tools.jackson.databind.ValueSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

Annotations
@Override
withConverterback to summary
protected DurationSerializer withConverter(DurationUnitConverter converter)
withFeaturesback to summary
protected JSR310FormattedSerializerBase<?> withFeatures(Boolean writeZoneId, Boolean writeNanoseconds)

Overrides tools.jackson.databind.ext.javatime.ser.JSR310FormattedSerializerBase.withFeatures.

Annotations
@Override
withFormatback to summary
protected DurationSerializer withFormat(DateTimeFormatter dtf, Boolean useTimestamp, JsonFormat.Shape shape)

Implements abstract tools.jackson.databind.ext.javatime.ser.JSR310FormattedSerializerBase.withFormat.

Annotations
@Override