toJson method
Converts this object into JSON format.
optimizeFor
lets the program know what information to include in the
JSON data map.
- OptimizeFor.put (the default value) is used when making a data map that is being placed in a PUT request. This only includes data that has changed.
- OptimizeFor.putFull is used when a parent object updates; so, all of the children are required to be present for the PUT request.
- OptimizeFor.post is used when making a data map for a POST request.
- OptimizeFor.dontOptimize is used to get all of the data contained in this object.
Throws InvalidIdException if any of the children's IDs or service's IDs
are empty and optimizeFor
is not set to OptimizeFor.dontOptimize.
Implementation
@override
Map<String, dynamic> toJson({OptimizeFor optimizeFor = OptimizeFor.put}) {
return {
ApiFields.type: type.value,
ApiFields.id: id,
ApiFields.idV1: idV1,
ApiFields.children: children
.map((child) => child.toJson(
optimizeFor: identical(optimizeFor, OptimizeFor.dontOptimize)
? optimizeFor
: OptimizeFor.putFull))
.toList(),
ApiFields.services: services
.map((service) => service.toJson(
optimizeFor: identical(optimizeFor, OptimizeFor.dontOptimize)
? optimizeFor
: OptimizeFor.putFull))
.toList(),
};
}