Class 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
: Hoursm
: Minutess
: Secondsms
: Millisecondsus
: Microsecondsns
: 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
-
Method Summary
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
-
Constructor Details
-
DurationSerializer
public DurationSerializer()Default constructor. Initializes the serializer forDuration
type.
-
-
Method Details
-
serialize
public void serialize(Duration duration, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider serializers) throws IOException Serializes aDuration
object into JSON.The serialization format depends on the
isEncodeDurationAsISO8601()
option inDataAPIClientOptions
. 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 classcom.fasterxml.jackson.databind.ser.std.StdSerializer<Duration>
- Parameters:
duration
- theDuration
object to serialize.gen
- theJsonGenerator
used to write JSON content.serializers
- theSerializerProvider
for accessing serialization configuration.- Throws:
IOException
- if an I/O error occurs during serialization.
-