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
    Constructor
    Description
    Default constructor for the deserializer.
  • Method Summary

    Modifier and Type
    Method
    Description
    deserialize(com.fasterxml.jackson.core.JsonParser parser, com.fasterxml.jackson.databind.DeserializationContext context)
    Deserializes a JSON value into a Duration object.
    static Duration
    parseDuration(String durationString)
    Parses a string representation of a duration 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

    • DurationHHMMSSDeserializer

      public DurationHHMMSSDeserializer()
      Default constructor for the deserializer.
  • Method Details

    • parseDuration

      public static Duration parseDuration(String durationString) throws NumberFormatException
      Parses a string representation of a duration into a Duration object.

      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 (returns Duration.ZERO)
      Returns:
      the parsed Duration
      Throws:
      NumberFormatException - if the string can't be parsed as a duration
      IllegalArgumentException - 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 a Duration object.

      This method reads the text value from the parser and delegates to parseDuration(String) for the actual parsing logic.

      Specified by:
      deserialize in class com.fasterxml.jackson.databind.JsonDeserializer<Duration>
      Parameters:
      parser - the JsonParser to read the value from
      context - context for the deserialization process
      Returns:
      the deserialized Duration object
      Throws:
      IOException - if the value can't be parsed as a duration, or if there's an issue with the parser
      IllegalArgumentException - if the parser is null
      See Also: