serialize method

  1. @override
void serialize(
  1. Set value,
  2. YamlGenerator generator,
  3. YamlSerializationContext 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(Set value, YamlGenerator generator, YamlSerializationContext serializer) {
  generator.writeStartSequence();
  for (final item in value) {
    serializer.serialize(item, generator);
  }
  generator.writeEndSequence();
}