serialize method

  1. @override
void serialize(
  1. List value,
  2. JsonGenerator generator,
  3. JsonSerializationContext serializer
)
override

Serializes an object of type T into an object using the provided Generator and SerializationContext.

Implementations should:

  • Write fields in the correct an object structure using generator
  • Apply the active NamingStrategy for key transformation
  • Use the SerializationContext for nested or custom serialization

Example

serializer.serialize(user, generator, provider);
final json = generator.toJsonString();
print(json); // {"id":1,"name":"Alice"}

Notes

  • Should write valid an object output
  • May recursively serialize nested objects
  • Must maintain structural integrity of objects and collections

Error Handling

Implementations should throw descriptive errors if:

  • A required field cannot be serialized
  • An unsupported type is encountered
  • an object structural consistency cannot be guaranteed

See also

Implementation

@override
void serialize(List value, JsonGenerator generator, JsonSerializationContext serializer) {
  generator.writeStartArray();

  for (final item in value) {
    serializer.serialize(item, generator);
  }

  generator.writeEndArray();
}