serialize method
Implementation
@override
String serialize(Object document, {bool withIncluded = false}) {
try {
JsonApiDocument jsonApiDoc = (document as JsonApiDocument);
Map<String, dynamic> jsonMap = {
'data': {
'id': jsonApiDoc.id,
'type': jsonApiDoc.type,
'attributes': jsonApiDoc.attributes,
'relationships': jsonApiDoc.relationships,
},
};
if (withIncluded) {
jsonMap['included'] = jsonApiDoc.included;
}
return json.encode(jsonMap);
} on TypeError {
throw ArgumentError('document must be a JsonApiDocument');
} on JsonUnsupportedObjectError {
throw SerializationException();
}
}