toJson method
Encodes this EntityReferenceList instance to JSON.
Fields:
EntityReferenceList
: the reference type.ids
: the entities IDs (if isIDsSet).entities
: the entities as JSON (if isEntitiesSet). See entitiesToJson.
Implementation
@override
Map<String, dynamic>? toJson([JsonEncoder? jsonEncoder]) {
if (isNull) {
return null;
}
if (isEntitiesSet) {
var entities = this.entities!;
var ids = this.ids;
var hasAnyEntity = entities.any((e) => e != null);
var hasAnyID = ids != null && ids.any((id) => id != null);
return <String, dynamic>{
'EntityReferenceList': typeName,
if (hasAnyID) 'ids': ids,
if (hasAnyEntity) 'entities': entitiesToJson(jsonEncoder),
};
} else if (isIDsSet) {
var ids = this.ids!;
var hasAnyID = ids.any((id) => id != null);
return <String, dynamic>{
'EntityReferenceList': typeName,
if (hasAnyID) 'ids': ids,
};
} else {
return <String, dynamic>{
'EntityReferenceList': typeName,
};
}
}