decodeSceneFromJson function

Scene decodeSceneFromJson(
  1. String json
)

Decodes a Scene from a JSON string.

Only schemaVersion = 2 is accepted.

Throws SceneJsonFormatException when the JSON is invalid, the schema version is unsupported, or validation fails.

Implementation

Scene decodeSceneFromJson(String json) {
  try {
    final raw = jsonDecode(json);
    if (raw is! Map<String, dynamic>) {
      throw SceneJsonFormatException('Root JSON must be an object.');
    }
    return decodeScene(raw);
  } on SceneJsonFormatException {
    rethrow;
  } on FormatException catch (error) {
    throw SceneJsonFormatException(error.message, error.source);
  }
}