ObjectDeserializer<T, P extends Parser, Context extends DeserializationContext<Parser>> class abstract

A generic, pluggable object deserializer responsible for converting structured data (parsed through a Parser) into fully-typed Dart objects.

ObjectDeserializer<T, Token> is a central abstraction in Jetleaf’s data-binding layer. It defines how raw parser tokens (JSON, YAML, custom formats, etc.) are transformed into instances of type T, using introspection metadata provided through Class and runtime utilities from DeserializationContext.

This interface enables:

  • Custom deserialization logic for user-defined types
  • Framework-level wiring for annotated model classes
  • Integration with converters and nested deserializers

Typical Usage

final parser = JsonParser.fromString(jsonString);
final context = DeserializationContext.default();

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

Responsibilities

  • Interpret parser tokens belonging to a structured object (maps, lists, primitives, nested types)
  • Construct Dart object instances through metadata in Class
  • Delegate nested values to the DeserializationContext
  • Support overrides, converters, and custom hooks

Object Construction Pipeline

Step Description
1 Determine if the type can be handled via canDeserialize
2 Read tokens from Parser sequentially
3 Match fields to Dart constructors or setters
4 Convert fields using nested deserializers or converters
5 Produce a fully constructed object instance of type T

Error Handling

Implementations should throw detailed, type-aware exceptions when:

  • A required field is missing
  • Type conversion fails
  • The token structure does not match the expected object shape
  • Construction of the object instance is not possible

Design Notes

  • Deserializers are fully pluggable, allowing frameworks or applications to register custom deserializers at runtime.
  • Integrates with Jetleaf’s reflection API (Class<T>) for metadata, enabling advanced features such as generic resolution, annotations, and runtime converters.
  • Token type is parameterized so deserializers may work across different parser backends (JSON, YAML, custom DSLs).

See Also

Implemented types
Implementers
Annotations
  • @Generic.new(ObjectDeserializer)

Constructors

ObjectDeserializer()
Creates a new ObjectDeserializer.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

canDeserialize(Class type) → bool
Returns whether the given type can be deserialized by the system.
deserialize(P parser, Context ctxt, Class toClass) → T?
Deserializes an object of type T using the given P and DeserializationContext.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
supports(DeserializationContext<Parser> context) → bool
Determines whether this deserializer supports the given deserialization context.
toClass() → Class<T>
Provides a contract for types capable of exposing their associated runtime Class metadata representation within the Jetleaf reflection system.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

CLASS → Class<ObjectDeserializer<dynamic, Parser, DeserializationContext<Parser>>>
Represents the ObjectDeserializer type for reflection-based discovery.
final