Class InstantSerializer

java.lang.Object
com.fasterxml.jackson.databind.JsonSerializer<Instant>
com.fasterxml.jackson.databind.ser.std.StdSerializer<Instant>
com.fasterxml.jackson.datatype.jsr310.ser.InstantSerializerBase<Instant>
com.fasterxml.jackson.datatype.jsr310.ser.InstantSerializer
All Implemented Interfaces:
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable, com.fasterxml.jackson.databind.jsonschema.SchemaAware, com.fasterxml.jackson.databind.ser.ContextualSerializer, Serializable

public class InstantSerializer extends InstantSerializerBase<Instant>
Serializer for Java 8 temporal Instants, OffsetDateTime, and ZonedDateTimes.
Since:
2.2
Author:
Nick Williams
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonSerializer

    com.fasterxml.jackson.databind.JsonSerializer.None
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final DateTimeFormatter
    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 com.fasterxml.jackson.databind.JavaType
    Lazily constructed JavaType representing type List<Integer>.
    protected final com.fasterxml.jackson.annotation.JsonFormat.Shape
     
    protected final Boolean
    Flag that indicates that numeric timestamp values must be written using nanosecond timestamps if the datatype supports such resolution, regardless of other settings.
    protected final Boolean
    Flag that indicates that serialization must be done as the Java timestamp, regardless of other settings.
    static final InstantSerializer
     

    Fields inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer

    _handledType
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
    protected
    InstantSerializer(InstantSerializer base, Boolean useTimestamp, Boolean useNanoseconds, DateTimeFormatter formatter)
     
    protected
    Deprecated.
    protected
    InstantSerializer(InstantSerializer base, Boolean useTimestamp, DateTimeFormatter formatter, com.fasterxml.jackson.annotation.JsonFormat.Shape shape)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected com.fasterxml.jackson.databind.JavaType
    _integerListType(com.fasterxml.jackson.databind.SerializerProvider prov)
     
    _useDateTimeFormatter(com.fasterxml.jackson.databind.SerializerProvider prov, com.fasterxml.jackson.annotation.JsonFormat.Value format)
     
    protected boolean
    _useTimestampExplicitOnly(com.fasterxml.jackson.databind.SerializerProvider provider)
     
    void
    acceptJsonFormatVisitor(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper visitor, com.fasterxml.jackson.databind.JavaType typeHint)
     
    com.fasterxml.jackson.databind.JsonSerializer<?>
    createContextual(com.fasterxml.jackson.databind.SerializerProvider prov, com.fasterxml.jackson.databind.BeanProperty property)
     
    com.fasterxml.jackson.databind.JsonNode
    getSchema(com.fasterxml.jackson.databind.SerializerProvider provider, Type typeHint)
     
    protected com.fasterxml.jackson.databind.SerializationFeature
    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.
    void
    serializeWithType(Instant value, com.fasterxml.jackson.core.JsonGenerator g, com.fasterxml.jackson.databind.SerializerProvider provider, com.fasterxml.jackson.databind.jsontype.TypeSerializer typeSer)
     
    protected boolean
    useNanoseconds(com.fasterxml.jackson.databind.SerializerProvider provider)
     
    protected boolean
    useTimestamp(com.fasterxml.jackson.databind.SerializerProvider provider)
     
    protected com.fasterxml.jackson.datatype.jsr310.ser.JSR310FormattedSerializerBase<?>
    withFeatures(Boolean writeZoneId)
    Deprecated.
    protected com.fasterxml.jackson.datatype.jsr310.ser.JSR310FormattedSerializerBase<?>
    withFeatures(Boolean writeZoneId, Boolean writeNanoseconds)
     
    protected com.fasterxml.jackson.datatype.jsr310.ser.JSR310FormattedSerializerBase<Instant>
    withFormat(Boolean useTimestamp, DateTimeFormatter formatter, com.fasterxml.jackson.annotation.JsonFormat.Shape shape)
     

    Methods inherited from class com.fasterxml.jackson.datatype.jsr310.ser.InstantSerializerBase

    _acceptTimestampVisitor, formatValue, serializationShape, serialize

    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • INSTANCE

      public static final InstantSerializer INSTANCE
    • _useTimestamp

      protected final Boolean _useTimestamp
      Flag that indicates that serialization must be done as the Java timestamp, regardless of other settings.
    • _useNanoseconds

      protected final Boolean _useNanoseconds
      Flag that indicates that numeric timestamp values must be written using nanosecond timestamps if the datatype supports such resolution, regardless of other settings.
    • _formatter

      protected final DateTimeFormatter _formatter
      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.
    • _shape

      protected final com.fasterxml.jackson.annotation.JsonFormat.Shape _shape
    • _integerListType

      protected transient volatile com.fasterxml.jackson.databind.JavaType _integerListType
      Lazily constructed JavaType representing type List<Integer>.
      Since:
      2.10
  • Constructor Details

  • Method Details

    • withFormat

      protected com.fasterxml.jackson.datatype.jsr310.ser.JSR310FormattedSerializerBase<Instant> withFormat(Boolean useTimestamp, DateTimeFormatter formatter, com.fasterxml.jackson.annotation.JsonFormat.Shape shape)
      Specified by:
      withFormat in class InstantSerializerBase<Instant>
    • withFeatures

      protected com.fasterxml.jackson.datatype.jsr310.ser.JSR310FormattedSerializerBase<?> withFeatures(Boolean writeZoneId, Boolean writeNanoseconds)
    • withFeatures

      @Deprecated protected com.fasterxml.jackson.datatype.jsr310.ser.JSR310FormattedSerializerBase<?> withFeatures(Boolean writeZoneId)
      Deprecated.
      Since:
      2.8
    • 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 interface com.fasterxml.jackson.databind.ser.ContextualSerializer
      Throws:
      com.fasterxml.jackson.databind.JsonMappingException
    • getSchema

      public com.fasterxml.jackson.databind.JsonNode getSchema(com.fasterxml.jackson.databind.SerializerProvider provider, Type typeHint)
      Specified by:
      getSchema in interface com.fasterxml.jackson.databind.jsonschema.SchemaAware
      Overrides:
      getSchema in class com.fasterxml.jackson.databind.ser.std.StdSerializer<T>
    • acceptJsonFormatVisitor

      public void acceptJsonFormatVisitor(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper visitor, com.fasterxml.jackson.databind.JavaType typeHint) throws com.fasterxml.jackson.databind.JsonMappingException
      Specified by:
      acceptJsonFormatVisitor in interface com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable
      Overrides:
      acceptJsonFormatVisitor in class com.fasterxml.jackson.databind.ser.std.StdSerializer<T>
      Throws:
      com.fasterxml.jackson.databind.JsonMappingException
    • _integerListType

      protected com.fasterxml.jackson.databind.JavaType _integerListType(com.fasterxml.jackson.databind.SerializerProvider prov)
    • getTimestampsFeature

      protected com.fasterxml.jackson.databind.SerializationFeature 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.

      Since:
      2.10
    • useTimestamp

      protected boolean useTimestamp(com.fasterxml.jackson.databind.SerializerProvider provider)
    • _useTimestampExplicitOnly

      protected boolean _useTimestampExplicitOnly(com.fasterxml.jackson.databind.SerializerProvider provider)
    • useNanoseconds

      protected boolean useNanoseconds(com.fasterxml.jackson.databind.SerializerProvider provider)
    • _useDateTimeFormatter

      protected DateTimeFormatter _useDateTimeFormatter(com.fasterxml.jackson.databind.SerializerProvider prov, com.fasterxml.jackson.annotation.JsonFormat.Value format)
    • serializeWithType

      public void serializeWithType(Instant value, com.fasterxml.jackson.core.JsonGenerator g, com.fasterxml.jackson.databind.SerializerProvider provider, com.fasterxml.jackson.databind.jsontype.TypeSerializer typeSer) throws IOException
      Overrides:
      serializeWithType in class com.fasterxml.jackson.databind.JsonSerializer<T>
      Throws:
      IOException