toJson method

  1. @override
Map<String, Object> toJson()
override

Serializes this resource to a JSON-encodable map.

Returns:

  • A map containing all relevant resource metadata
  • Should include at minimum a 'type' field identifying the resource kind
  • Must contain only JSON-encodable values

Implementation Requirements:

  • Must be overridden by subclasses
  • Should include all identifying metadata
  • Should maintain backward compatibility

Example Output:

{
  "type": "font",
  "family": "Roboto",
  "files": ["Roboto-Regular.ttf", "Roboto-Bold.ttf"]
}

Implementation

@override
Map<String, Object> toJson() {
  if(exists()) {
    return _asset!.toJson();
  }

  throw _throwIfNotFound();
}