serialize method
Iterable<Object?>
serialize(
- Serializers serializers,
- Shape object, {
- FullType specifiedType = FullType.unspecified,
override
Serializes object
.
Use serializers
as needed for nested serialization. Information about
the type being serialized is provided in specifiedType
.
Returns an Iterable of values that can be represented as structured JSON: booleans, integers, doubles, Strings and Iterables.
TODO(davidmorgan): document the wire format.
Implementation
@override
Iterable<Object?> serialize(
Serializers serializers,
Shape object, {
FullType specifiedType = FullType.unspecified,
}) {
final map = serializers.serialize(
object,
specifiedType: FullType(object.getType().type),
) as Map<String, Object?>;
map['type'] = object.getType().name;
map.removeWhere(
(key, value) =>
value == null ||
(value is Map && value.isEmpty) ||
(value is List && value.isEmpty),
);
return map.entries.expand(
(entry) => [
entry.key,
entry.value,
],
);
}