serialize abstract method
void
serialize(
- T value,
- G generator,
- Context serializer
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
void serialize(T value, G generator, Context serializer);