Class DurationHHMMSSDeserializer
java.lang.Object
com.fasterxml.jackson.databind.JsonDeserializer<Duration>
dev.jcputney.elearning.parser.input.common.serialization.DurationHHMMSSDeserializer
- All Implemented Interfaces:
com.fasterxml.jackson.databind.deser.NullValueProvider
public class DurationHHMMSSDeserializer
extends com.fasterxml.jackson.databind.JsonDeserializer<Duration>
Custom deserializer for
Duration objects, allowing HH:MM:SS duration strings to be parsed
into Duration instances.
This deserializer supports durations in the format HH:MM:SS, where HH represents
hours, MM represents minutes, and SS represents seconds. It doesn't support days, 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.static DurationparseDuration(String durationString) Parses a string representation of a duration 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
-
DurationHHMMSSDeserializer
public DurationHHMMSSDeserializer()Default constructor for the deserializer.
-
-
Method Details
-
parseDuration
Parses a string representation of a duration into aDurationobject.This method supports the following formats:
- Numeric values (interpreted as seconds)
- HH:MM:SS format (hours:minutes:seconds)
- MM:SS format (minutes:seconds)
- SS format (seconds only)
Examples:
- "3600" → 1 hour
- "01:30:45" → 1 hour, 30 minutes, 45 seconds
- "30:45" → 30 minutes, 45 seconds
- "45" → 45 seconds
- Parameters:
durationString- the string to parse, can be empty or null (returnsDuration.ZERO)- Returns:
- the parsed
Duration - Throws:
NumberFormatException- if the string can't be parsed as a durationIllegalArgumentException- if the string format is invalid
-
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 reads the text value from the parser and delegates to
parseDuration(String)for the actual parsing logic.- 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- See Also:
-