serialize static method
Serializes the given object into a JSON string.
Uses the provided options or merges them with the default options. The serialization process uses registered converters to handle type conversion.
@param object The object to serialize to JSON.
@param options Optional serializer options. If provided, will be merged with default options.
@returns The JSON string representation of the object.
Implementation
static String serialize(Object? object, [JsonSerializerOptions? options]) {
final mergedOptions = JsonSerializer.options.merge(options);
if (object == null) {
return JsonWriter.encode(null);
}
final typeName = object.runtimeType.toString();
final encoded = encode(
object,
DartParser.parseType(typeName),
mergedOptions,
);
final normalized = _normalizeForJson(encoded, mergedOptions);
return JsonWriter.encode(normalized);
}