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
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
: Hoursm
: Minutess
: Secondsms
: Millisecondsus
orµs
: Microsecondsns
: 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
-
Method Summary
Modifier and TypeMethodDescriptiondeserialize
(com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.databind.DeserializationContext ctxt) Deserializes a JSON string into aDuration
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
-
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 aDuration
object.Supports parsing either ISO-8601 duration strings or custom human-readable formats based on the configuration provided by
DataAPIClientOptions
.- Specified by:
deserialize
in classcom.fasterxml.jackson.databind.JsonDeserializer<Duration>
- Parameters:
p
- theJsonParser
providing access to the JSON content.ctxt
- theDeserializationContext
for contextual information.- Returns:
- the deserialized
Duration
object, ornull
if the input string is empty. - Throws:
IOException
- if the input string is invalid or contains an unsupported time unit.
-