deserialize method

  1. @override
LocalDate? deserialize(
  1. P parser,
  2. DC ctxt,
  3. Class toClass
)
override

Deserializes an object of type T using the given P and DeserializationContext.

This method reads tokens from the provided parser, interprets them according to the target type metadata, and reconstructs an instance of T.

Example

final user = UserDeserializer().deserialize(parser, context, Class<User>());

Responsibilities

  • Interpret object tokens from the parser sequentially
  • Use DeserializationContext for nested deserialization and converters
  • Handle complex object graphs, lists, and maps recursively
  • Return a fully reconstructed object of type T

Error Handling

Should throw a descriptive exception if:

  • object structure mismatches the expected type
  • Required fields are missing or invalid
  • Type conversion fails during object creation

See also

Implementation

@override
LocalDate? deserialize(P parser, DC ctxt, Class toClass) {
  final raw = parser.getCurrentValue();

  if (raw == null) {
    return null;
  }

  try {
    return ctxt.getConversionService().convert(raw, Class<LocalDate>());
  } catch (_) {
    if (raw is String) {
      return LocalDate.parse(raw);
    }

    throw InvalidFormatException('Invalid LocalDate format. Expected ISO-8601 (e.g. "2025-10-28") but received $raw');
  }
}