Class DurationDeserializer

java.lang.Object
com.fasterxml.jackson.databind.JsonDeserializer<Duration>
com.datastax.astra.internal.serdes.tables.DurationDeserializer
All Implemented Interfaces:
com.fasterxml.jackson.databind.deser.NullValueProvider

public class DurationDeserializer extends com.fasterxml.jackson.databind.JsonDeserializer<Duration>
A custom deserializer for Duration objects, extending JsonDeserializer. This deserializer supports multiple formats for parsing duration strings.

Two parsing modes are supported based on configuration:

  • ISO-8601 format: Parses strings like "PT1H30M" if ISO-8601 encoding is enabled.
  • Custom format: Parses human-readable durations, such as "1h30m", with support for a variety of time units, including hours, minutes, seconds, milliseconds, microseconds, and nanoseconds.

The following units are supported in the custom format:

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

Negative durations are supported by prefixing the string with a - sign (e.g., "-1h30m").

  • Nested Class Summary

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

    com.fasterxml.jackson.databind.JsonDeserializer.None
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    deserialize(com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.databind.DeserializationContext ctxt)
    Deserializes a JSON string into a Duration object.

    Methods inherited from class com.fasterxml.jackson.databind.JsonDeserializer

    deserialize, deserializeWithType, deserializeWithType, findBackReference, getAbsentValue, getDelegatee, getEmptyAccessPattern, getEmptyValue, getEmptyValue, getKnownPropertyNames, getNullAccessPattern, getNullValue, getNullValue, getObjectIdReader, handledType, isCachable, logicalType, replaceDelegatee, supportsUpdate, unwrappingDeserializer

    Methods inherited from class java.lang.Object

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

    • DurationDeserializer

      public DurationDeserializer()
      Default constructor.
  • Method Details

    • deserialize

      public Duration deserialize(com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.databind.DeserializationContext ctxt) throws IOException
      Deserializes a JSON string into a Duration object.

      Supports parsing either ISO-8601 duration strings or custom human-readable formats based on the configuration provided by DataAPIClientOptions.

      Specified by:
      deserialize in class com.fasterxml.jackson.databind.JsonDeserializer<Duration>
      Parameters:
      p - the JsonParser providing access to the JSON content.
      ctxt - the DeserializationContext for contextual information.
      Returns:
      the deserialized Duration object, or null if the input string is empty.
      Throws:
      IOException - if the input string is invalid or contains an unsupported time unit.