Class DurationSerializer

java.lang.Object
com.fasterxml.jackson.databind.JsonSerializer<Duration>
com.fasterxml.jackson.databind.ser.std.StdSerializer<Duration>
com.datastax.astra.internal.serdes.tables.DurationSerializer
All Implemented Interfaces:
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable, com.fasterxml.jackson.databind.jsonschema.SchemaAware, Serializable

public class DurationSerializer extends com.fasterxml.jackson.databind.ser.std.StdSerializer<Duration>
A custom serializer for Duration objects, extending StdSerializer. This serializer supports two serialization formats for durations:
  • ISO-8601 format: Encodes the duration as an ISO-8601 string (e.g., "PT1H30M").
  • Compact format: Encodes the duration as a human-readable string with unit suffixes (e.g., "1h30m").

The format used is determined by the isEncodeDurationAsISO8601() option in DataAPIClientOptions. If the duration is null, it serializes as a JSON null.

Supported time units in the compact format:

  • h: Hours
  • m: Minutes
  • s: Seconds
  • ms: Milliseconds
  • us: Microseconds
  • ns: Nanoseconds

Negative durations are serialized with a - prefix (e.g., "-1h30m").

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 inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer

    _handledType
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    serialize(Duration duration, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider serializers)
    Serializes a Duration object into JSON.

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

    _neitherNull, _nonEmpty, acceptJsonFormatVisitor, createSchemaNode, createSchemaNode, findAnnotatedContentSerializer, findContextualConvertingSerializer, findConvertingContentSerializer, findFormatFeature, findFormatOverrides, findIncludeOverrides, findPropertyFilter, getSchema, 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, serializeWithType, unwrappingSerializer, usesObjectId, withFilterId, withIgnoredProperties

    Methods inherited from class java.lang.Object

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

    • DurationSerializer

      public DurationSerializer()
      Default constructor. Initializes the serializer for Duration type.
  • Method Details

    • serialize

      public void serialize(Duration duration, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider serializers) throws IOException
      Serializes a Duration object into JSON.

      The serialization format depends on the isEncodeDurationAsISO8601() option in DataAPIClientOptions. If enabled, the duration is serialized in ISO-8601 format. Otherwise, it is serialized in a compact human-readable format using time unit suffixes.

      Specified by:
      serialize in class com.fasterxml.jackson.databind.ser.std.StdSerializer<Duration>
      Parameters:
      duration - the Duration object to serialize.
      gen - the JsonGenerator used to write JSON content.
      serializers - the SerializerProvider for accessing serialization configuration.
      Throws:
      IOException - if an I/O error occurs during serialization.