Class DurationIso8601Deserializer
java.lang.Object
com.fasterxml.jackson.databind.JsonDeserializer<Duration>
dev.jcputney.elearning.parser.input.common.serialization.DurationIso8601Deserializer
- All Implemented Interfaces:
com.fasterxml.jackson.databind.deser.NullValueProvider
public class DurationIso8601Deserializer
extends com.fasterxml.jackson.databind.JsonDeserializer<Duration>
Custom deserializer for
Duration objects, allowing ISO 8601 duration strings to be parsed
into Duration instances.
This deserializer supports durations in the format PnDTnHnMnS, where n represents
days, hours, minutes, or seconds. It doesn't support months or years, as these aren't compatible
with Duration.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonDeserializer
com.fasterxml.jackson.databind.JsonDeserializer.None -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondeserialize(com.fasterxml.jackson.core.JsonParser parser, com.fasterxml.jackson.databind.DeserializationContext context) Deserializes a JSON value into aDurationobject.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
-
DurationIso8601Deserializer
public DurationIso8601Deserializer()Default constructor for the deserializer.
-
-
Method Details
-
deserialize
public Duration deserialize(com.fasterxml.jackson.core.JsonParser parser, com.fasterxml.jackson.databind.DeserializationContext context) throws IOException Deserializes a JSON value into aDurationobject.This method supports multiple duration formats:
- Empty string or null, returns
Duration.ZERO - Numeric values, interpreted as seconds
- ISO 8601 duration format, for example, "PT1H30M45S"
- HH:MM:SS format, delegated to
DurationHHMMSSDeserializer.parseDuration(java.lang.String)
- Specified by:
deserializein classcom.fasterxml.jackson.databind.JsonDeserializer<Duration>- Parameters:
parser- the JsonParser to read the value fromcontext- context for the deserialization process- Returns:
- the deserialized
Durationobject - Throws:
IOException- if the value can't be parsed as a duration, or if there's an issue with the parserIllegalArgumentException- if the parser is null
- Empty string or null, returns
-