ResourceContent.fromJson constructor
ResourceContent.fromJson(
- Map<String, dynamic> json
)
Implementation
factory ResourceContent.fromJson(Map<String, dynamic> json) {
// Handle both 2025 format (nested) and older format (flat)
final resource = json['resource'] as Map<String, dynamic>?;
if (resource != null) {
// 2025 format with nested resource
return ResourceContent(
uri: resource['uri'] as String,
text: resource['text'] as String?,
blob: resource['blob'] as String?,
mimeType: resource['mimeType'] as String?,
annotations: json['annotations'] as Map<String, dynamic>?,
);
} else {
// Older flat format
return ResourceContent(
uri: json['uri'] as String,
text: json['text'] as String?,
blob: json['blob'] as String?,
mimeType: json['mimeType'] as String?,
annotations: json['annotations'] as Map<String, dynamic>?,
);
}
}