Top Fields Constructors Methods
tools.jackson.databind.ser.jdk

public abstract Class DateTimeSerializerBase<T>

extends StdScalarSerializer<T>
Class Inheritance
Known Direct Subclasses
tools.jackson.databind.ser.jdk.JavaUtilDateSerializer, tools.jackson.databind.ext.sql.JavaSqlDateSerializer, tools.jackson.databind.ser.jdk.JavaUtilCalendarSerializer
Imports
java.text.DateFormat, .SimpleDateFormat, java.util.Date, .Locale, .TimeZone, java.util.concurrent.atomic.AtomicReference, com.fasterxml.jackson.annotation.JsonFormat, tools.jackson.core.JacksonException, .JsonGenerator, .JsonParser, tools.jackson.databind.*, tools.jackson.databind.cfg.DateTimeFeature, tools.jackson.databind.jsonFormatVisitors.*, tools.jackson.databind.ser.std.StdScalarSerializer, tools.jackson.databind.util.StdDateFormat

Field Summary

Modifier and TypeField and Description
protected final DateFormat
_customFormat

Specific format to use, if not default format: non null value also indicates that serialization is to be done as JSON String, not numeric timestamp, unless _useTimestamp is true.

protected final AtomicReference<DateFormat>
_reusedCustomFormat

If _customFormat is used, we will try to reuse instances in simplest possible form; thread-safe, but without overhead of ThreadLocal (not from code, but wrt retaining of possibly large number of format instances over all threads, properties with custom formats).

protected final Boolean
_useTimestamp

Flag that indicates that serialization must be done as the Java timestamp, regardless of other settings.

Constructor Summary

AccessConstructor and Description
protected
DateTimeSerializerBase(Class<T> type, Boolean useTimestamp, DateFormat customFormat)

Method Summary

Modifier and TypeMethod and Description
protected void
_acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint, boolean asNumber)

protected boolean
protected void
protected abstract long
_timestamp(T value)

public void
public ValueSerializer<?>
createContextual(SerializationContext serializers, BeanProperty property)

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

public boolean
isEmpty(SerializationContext serializers, T value)

Overrides tools.jackson.databind.ValueSerializer.isEmpty.

Method called to check whether given serializable value is considered "empty" value (for purposes of suppressing serialization of empty values).

public abstract void
serialize(T value, JsonGenerator gen, SerializationContext serializers)

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.

public abstract DateTimeSerializerBase<T>
withFormat(Boolean timestamp, DateFormat customFormat)

Inherited from tools.jackson.databind.ser.std.StdScalarSerializer:
serializeWithType

Field Detail

_customFormatback to summary
protected final DateFormat _customFormat

Specific format to use, if not default format: non null value also indicates that serialization is to be done as JSON String, not numeric timestamp, unless _useTimestamp is true.

_reusedCustomFormatback to summary
protected final AtomicReference<DateFormat> _reusedCustomFormat

If _customFormat is used, we will try to reuse instances in simplest possible form; thread-safe, but without overhead of ThreadLocal (not from code, but wrt retaining of possibly large number of format instances over all threads, properties with custom formats).

Since
2.9
_useTimestampback to summary
protected final Boolean _useTimestamp

Flag that indicates that serialization must be done as the Java timestamp, regardless of other settings.

Constructor Detail

DateTimeSerializerBaseback to summary
protected DateTimeSerializerBase(Class<T> type, Boolean useTimestamp, DateFormat customFormat)

Method Detail

_acceptJsonFormatVisitorback to summary
protected void _acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint, boolean asNumber)
_asTimestampback to summary
protected boolean _asTimestamp(SerializationContext serializers)
_serializeAsStringback to summary
protected void _serializeAsString(Date value, JsonGenerator g, SerializationContext provider) throws JacksonException
_timestampback to summary
protected abstract long _timestamp(T value)
acceptJsonFormatVisitorback to summary
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)

Overrides tools.jackson.databind.ser.std.StdScalarSerializer.acceptJsonFormatVisitor.

Implements tools.jackson.databind.jsonFormatVisitors.JsonFormatVisitable.acceptJsonFormatVisitor.

Doc from tools.jackson.databind.ser.std.StdSerializer.acceptJsonFormatVisitor.

Default implementation specifies no format. This behavior is usually overriden by custom serializers.

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

Overrides tools.jackson.databind.ValueSerializer.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
isEmptyback to summary
public boolean isEmpty(SerializationContext serializers, T value)

Overrides tools.jackson.databind.ValueSerializer.isEmpty.

Doc from tools.jackson.databind.ValueSerializer.isEmpty.

Method called to check whether given serializable value is considered "empty" value (for purposes of suppressing serialization of empty values).

Default implementation will consider only null values to be empty.

Annotations
@Override
serializeback to summary
public abstract void serialize(T value, JsonGenerator gen, SerializationContext serializers) 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
withFormatback to summary
public abstract DateTimeSerializerBase<T> withFormat(Boolean timestamp, DateFormat customFormat)