deserialize method
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
Map? deserialize(XmlParser parser, XmlDeserializationContext ctxt, Class toClass) {
final map = <String, Object>{};
while (parser.nextToken()) {
if (parser.getCurrentToken() == XmlToken.END_ELEMENT) {
break;
}
if (parser.getCurrentToken() == XmlToken.START_ELEMENT) {
final key = parser.getElementName() ?? 'unknown';
final valueType = toClass.componentType() ?? Class<Object>();
final value = ctxt.deserialize(parser, valueType);
map[key] = value;
}
}
return map;
}