deserialize method

Map<String, dynamic> deserialize(
  1. String raw
)

Deserialize a raw string into a JSON map.

Throws BridgeError with ErrorCode.parseError if the input is invalid.

Implementation

Map<String, dynamic> deserialize(String raw) {
  try {
    final decoded = jsonDecode(raw);
    if (decoded is! Map<String, dynamic>) {
      throw BridgeError.parseError('Expected JSON object');
    }
    return decoded;
  } on FormatException catch (e) {
    throw BridgeError.parseError('Invalid JSON: ${e.message}');
  }
}