@@ -29,9 +29,6 @@ void _log(obj) {
29
29
*/
30
30
@proxy
31
31
class JsonObject <E > extends Object implements Map , Iterable {
32
- /// The original JSON string
33
- var _jsonString;
34
-
35
32
/// Contains either a [List] or [Map]
36
33
var _objectData;
37
34
@@ -99,8 +96,7 @@ class JsonObject<E> extends Object implements Map, Iterable {
99
96
if (t == null ) {
100
97
t = new JsonObject ();
101
98
}
102
- t._jsonString = _jsonString;
103
- t._objectData = decoder.convert (t._jsonString);
99
+ t._objectData = decoder.convert (_jsonString);
104
100
t._extractElements (t._objectData);
105
101
t.isExtendable = false ;
106
102
return t;
@@ -109,16 +105,18 @@ class JsonObject<E> extends Object implements Map, Iterable {
109
105
110
106
/** An alternate constructor, allows creating directly from a map
111
107
* rather than a json string.
108
+ *
109
+ * If [recursive] is true, all values of the map will be converted
110
+ * to [JsonObject] s as well. The default value is [true] .
112
111
*/
113
- JsonObject .fromMap (Map map) {
114
- _jsonString = encoder.convert (map);
112
+ JsonObject .fromMap (Map map, [bool recursive = true ]) {
115
113
_objectData = map;
116
- _extractElements (_objectData);
114
+ if (recursive)
115
+ _extractElements (_objectData);
117
116
isExtendable = false ;
118
117
}
119
118
120
119
static JsonObject toTypedJsonObject (JsonObject src, JsonObject dest) {
121
- dest._jsonString = src._jsonString;
122
120
dest._objectData = src._objectData;
123
121
dest.isExtendable = false ;
124
122
return dest;
@@ -263,14 +261,14 @@ class JsonObject<E> extends Object implements Map, Iterable {
263
261
264
262
@deprecated
265
263
E firstMatching (bool test (E value), { E orElse () : null }) {
266
- if (orElse != null ) this .toIterable ().firstWhere (test, orElse: orElse);
267
- else this .toIterable ().firstWhere (test);
264
+ if (orElse != null ) return this .toIterable ().firstWhere (test, orElse: orElse);
265
+ else return this .toIterable ().firstWhere (test);
268
266
}
269
267
270
268
@deprecated
271
269
E lastMatching (bool test (E value), {E orElse () : null }) {
272
- if (orElse != null ) this .toIterable ().lastWhere (test, orElse: orElse);
273
- else this .toIterable ().lastWhere (test);
270
+ if (orElse != null ) return this .toIterable ().lastWhere (test, orElse: orElse);
271
+ else return this .toIterable ().lastWhere (test);
274
272
}
275
273
276
274
@deprecated
0 commit comments