@@ -147,13 +147,11 @@ class _Parser {
147
147
148
148
/// Decodes Link from [json] . Returns the decoded object.
149
149
/// If the [json] has incorrect format, throws [FormatException] .
150
- Link _link (Object json) {
151
- if (json is String ) return Link (Uri .parse (json));
152
- if (json is Map ) {
153
- return Link (Uri .parse (json['href' ]))..meta.addAll (meta (json));
154
- }
155
- throw FormatException ('Invalid JSON' );
156
- }
150
+ Link _link (Object json) => switch (json) {
151
+ String () => Link (Uri .parse (json)),
152
+ Map () => Link (Uri .parse (json['href' ]))..meta.addAll (meta (json)),
153
+ _ => throw FormatException ('Invalid JSON' )
154
+ };
157
155
158
156
Map <String , Object ?> _getAttributes (Map json) =>
159
157
json.get <Map <String , Object ?>>('attributes' , orGet: () => {});
@@ -166,25 +164,19 @@ class _Parser {
166
164
.get <Map >('relationships' , orGet: () => {})
167
165
.map ((key, value) => MapEntry (key, newRelationship (value)));
168
166
169
- Relationship _rel (data) {
170
- if (data == null ) return ToOne .empty ();
171
- if (data is Map ) return ToOne (identifier (data));
172
- if (data is List ) return ToMany (data.whereType <Map >().map (identifier));
173
- throw FormatException ('Invalid relationship object' );
174
- }
175
-
176
- NewRelationship _newRel (data) {
177
- if (data == null ) {
178
- return NewToOne .empty ();
179
- }
180
- if (data is Map ) {
181
- return NewToOne (newIdentifier (data));
182
- }
183
- if (data is List ) {
184
- return NewToMany (data.whereType <Map >().map (newIdentifier));
185
- }
186
- throw FormatException ('Invalid relationship object' );
187
- }
167
+ Relationship _rel (data) => switch (data) {
168
+ null => ToOne .empty (),
169
+ Map () => ToOne (identifier (data)),
170
+ List () => ToMany (data.whereType <Map >().map (identifier)),
171
+ _ => throw FormatException ('Invalid relationship object' )
172
+ };
173
+
174
+ NewRelationship _newRel (data) => switch (data) {
175
+ null => NewToOne .empty (),
176
+ Map () => NewToOne (newIdentifier (data)),
177
+ List () => NewToMany (data.whereType <Map >().map (newIdentifier)),
178
+ _ => throw FormatException ('Invalid relationship object' )
179
+ };
188
180
}
189
181
190
182
extension _TypedGeter on Map {
0 commit comments