public abstract class DateTimeSerializerBase<T> extends StdScalarSerializer<T> implements ContextualSerializer
JsonSerializer.None
Modifier and Type | Field and Description |
---|---|
protected 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 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 Boolean |
_useTimestamp
Flag that indicates that serialization must be done as the
Java timestamp, regardless of other settings.
|
_handledType
Modifier | Constructor and Description |
---|---|
protected |
DateTimeSerializerBase(Class<T> type,
Boolean useTimestamp,
DateFormat customFormat) |
Modifier and Type | Method and Description |
---|---|
protected void |
_acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor,
JavaType typeHint,
boolean asNumber) |
protected boolean |
_asTimestamp(SerializerProvider serializers) |
protected void |
_serializeAsString(Date value,
com.fasterxml.jackson.core.JsonGenerator g,
SerializerProvider provider) |
protected abstract long |
_timestamp(T value) |
void |
acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor,
JavaType typeHint)
Default implementation specifies no format.
|
JsonSerializer<?> |
createContextual(SerializerProvider serializers,
BeanProperty property)
Method called to see if a different (or differently configured) serializer
is needed to serialize values of specified property.
|
JsonNode |
getSchema(SerializerProvider serializers,
Type typeHint)
Default implementation simply claims type is "string"; usually
overriden by custom serializers.
|
boolean |
isEmpty(SerializerProvider serializers,
T value)
Method called to check whether given serializable value is
considered "empty" value (for purposes of suppressing serialization
of empty values).
|
abstract void |
serialize(T value,
com.fasterxml.jackson.core.JsonGenerator gen,
SerializerProvider serializers)
Method that can be called to ask implementation to serialize
values of type this serializer handles.
|
abstract DateTimeSerializerBase<T> |
withFormat(Boolean timestamp,
DateFormat customFormat) |
serializeWithType
_neitherNull, _nonEmpty, createSchemaNode, createSchemaNode, findAnnotatedContentSerializer, findContextualConvertingSerializer, findConvertingContentSerializer, findFormatFeature, findFormatOverrides, findIncludeOverrides, findPropertyFilter, getSchema, handledType, isDefaultSerializer, visitArrayFormat, visitArrayFormat, visitFloatFormat, visitIntFormat, visitIntFormat, visitStringFormat, visitStringFormat, wrapAndThrow, wrapAndThrow
getDelegatee, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, unwrappingSerializer, usesObjectId, withFilterId
protected final Boolean _useTimestamp
protected final DateFormat _customFormat
_useTimestamp
is true.protected final AtomicReference<DateFormat> _reusedCustomFormat
_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 DateTimeSerializerBase(Class<T> type, Boolean useTimestamp, DateFormat customFormat)
public abstract DateTimeSerializerBase<T> withFormat(Boolean timestamp, DateFormat customFormat)
public JsonSerializer<?> createContextual(SerializerProvider serializers, BeanProperty property) throws JsonMappingException
ContextualSerializer
createContextual
in interface ContextualSerializer
serializers
- Serializer provider to use for accessing config, other serializersproperty
- Method or field that represents the property
(and is used to access value to serialize).
Should be available; but there may be cases where caller cannot provide it and
null is passed instead (in which case impls usually pass 'this' serializer as is)JsonMappingException
public boolean isEmpty(SerializerProvider serializers, T value)
JsonSerializer
Default implementation will consider only null values to be empty.
NOTE: replaces JsonSerializer.isEmpty(Object)
, which was deprecated in 2.5
isEmpty
in class JsonSerializer<T>
protected abstract long _timestamp(T value)
public JsonNode getSchema(SerializerProvider serializers, Type typeHint)
StdSerializer
getSchema
in interface SchemaAware
getSchema
in class StdScalarSerializer<T>
serializers
- The serializer provider.typeHint
- A hint about the type.public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
StdSerializer
acceptJsonFormatVisitor
in interface JsonFormatVisitable
acceptJsonFormatVisitor
in class StdScalarSerializer<T>
typeHint
- Type of element (entity like property) being visitedJsonMappingException
public abstract void serialize(T value, com.fasterxml.jackson.core.JsonGenerator gen, SerializerProvider serializers) throws IOException
JsonSerializer
serialize
in class StdSerializer<T>
value
- Value to serialize; can not be null.gen
- Generator used to output resulting Json contentserializers
- Provider that can be used to get serializers for
serializing Objects value contains, if any.IOException
protected boolean _asTimestamp(SerializerProvider serializers)
protected void _acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint, boolean asNumber) throws JsonMappingException
JsonMappingException
protected void _serializeAsString(Date value, com.fasterxml.jackson.core.JsonGenerator g, SerializerProvider provider) throws IOException
IOException
Copyright © 2008–2022 FasterXML. All rights reserved.