DartJsonSerializationAdapter class final

Provides a generic serialization and deserialization adapter for Dart classes using reflection within the JetLeaf JSON subsystem.

The DartJsonSerializationAdapter serves as a bridge between the JSON representation and a Dart class type, handling field mapping, annotations, and type conversions.

Core Responsibilities

  • Deserialize JSON objects into Dart class instances
  • Serialize Dart class instances into JSON objects
  • Respect field-level annotations such as:
  • Integrate with JsonDeserializationContext and JsonSerializationContext for naming strategies, type conversions, and feature flags

Example

final adapter = DartJsonSerializationAdapter(Class.forType(User));
final userJson = '{ "name": "Alice", "age": 30 }';
final parser = JsonParser(userJson);
final user = adapter.deserialize(parser, context, Class.forType(User));

final generator = JsonGenerator();
adapter.serialize(user, generator, serializerContext);

Notes

  • This adapter relies heavily on reflection (Class metadata) to access fields and methods of the Dart class.
  • Supports both standard deserialization paths and custom converters per field.
  • Honors serialization and deserialization feature flags such as ignoring null values or failing on unknown properties.

See also

Inheritance

Constructors

DartJsonSerializationAdapter(Class _type)
Creates a new DartJsonSerializationAdapter for the specified Dart Class.

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.
override
canSerialize(Class type) bool
Returns whether the given type can be serialized by the system.
override
deserialize(JsonParser parser, JsonDeserializationContext ctxt, Class toClass) Object?
Deserializes an object of type T using the given P and DeserializationContext.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
serialize(Object value, JsonGenerator generator, JsonSerializationContext serializer) → void
Serializes an object of type T into an object using the provided Generator and SerializationContext.
override
supports(DeserializationContext<Parser> context) bool
Determines whether this deserializer supports the given deserialization context.
inherited
supportsContext(SerializationContext<Generator> context) bool
Determines whether this serializer supports the given serialization context.
inherited
toClass() → Class<Object>
Provides a contract for types capable of exposing their associated runtime Class metadata representation within the JetLeaf reflection system.
toString() String
A string representation of this object.
inherited

Operators

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