Showing 2 of 3 files from the diff.

@@ -19,14 +19,7 @@
Loading
19 19
  /// a cache of the decoded value is provided.
20 20
  factory JsonString(String source, {bool enableCache = false}) {
21 21
    assert(source != null);
22 -
    try {
23 -
      return _constructJsonString(source, enableCache);
24 -
    } on FormatException catch (e) {
25 -
      throw JsonFormatException.fromParent(e);
26 -
    } catch (_) {
27 -
      throw JsonFormatException(
28 -
          "This source does not represent a valid JSON.", source);
29 -
    }
22 +
    return _constructJsonString(source, enableCache);
30 23
  }
31 24
32 25
  /// Constructs a [JsonString] if [source] is a valid JSON.
@@ -61,7 +54,7 @@
Loading
61 54
  /// [T] must be a primitive type (int, double, bool or String).
62 55
  static JsonString encodePrimitiveValue<T>(T value) {
63 56
    assert(value != null);
64 -
    return wrapEncodingOperation(() {
57 +
    return wrapJsonUtilOperation(() {
65 58
      final encodable = EncodableValue.fromPrimitiveValue<T>(value);
66 59
      return JsonString._(encodable.encode(), null);
67 60
    });
@@ -72,7 +65,7 @@
Loading
72 65
  /// [T] must be a primitive type (int, double, bool or String).
73 66
  static JsonString encodePrimitiveList<T>(List<T> list) {
74 67
    assert(list != null);
75 -
    return wrapEncodingOperation(() {
68 +
    return wrapJsonUtilOperation(() {
76 69
      final encodable = EncodableValue.fromPrimitiveList<T>(list);
77 70
      return JsonString._(encodable.encode(), null);
78 71
    });
@@ -87,7 +80,7 @@
Loading
87 80
  static JsonString encodeObject<T extends Object>(T value,
88 81
      {JsonObjectEncoder<T> encoder}) {
89 82
    assert(value != null);
90 -
    return wrapEncodingOperation(() {
83 +
    return wrapJsonUtilOperation(() {
91 84
      final dynamicMap = disassembleObject<T>(value, builder: encoder);
92 85
      final encodable = EncodableValue.map(dynamicMap);
93 86
      return JsonString._(encodable.encode(), null);
@@ -100,7 +93,7 @@
Loading
100 93
  static JsonString encodeObjectList<T extends Object>(List<T> list,
101 94
      {JsonObjectEncoder<T> encoder}) {
102 95
    assert(list != null);
103 -
    return wrapEncodingOperation(() {
96 +
    return wrapJsonUtilOperation(() {
104 97
      final dynamicList = disassembleObjectList<T>(list, builder: encoder);
105 98
      final encodable = EncodableValue.list(dynamicList);
106 99
      return JsonString._(encodable.encode(), null);
@@ -112,21 +105,21 @@
Loading
112 105
  /// The JSON data directly decoded as a dynamic type.
113 106
  ///
114 107
  /// (this is the most general one.)
115 -
  dynamic get decodedValue => wrapDecodingOperation(() => _decodedValue.value);
108 +
  dynamic get decodedValue => wrapJsonUtilOperation(() => _decodedValue.value);
116 109
117 110
  /// The JSON data decoded as an instance of [Map<String, dynamic>].
118 111
  ///
119 112
  /// The JSON data must be a JSON object or it will throw
120 113
  /// a [JsonDecodingError].
121 114
  Map<String, dynamic> get decodedValueAsMap =>
122 -
      wrapDecodingOperation(() => _decodedValue.asMap());
115 +
      wrapJsonUtilOperation(() => _decodedValue.asMap());
123 116
124 117
  /// The JSON data decoded as an instance of [List<dynamic>].
125 118
  ///
126 119
  /// The JSON data must be a JSON list or it will throw
127 120
  /// a [JsonDecodingError].
128 121
  List<dynamic> get decodedValueAsList =>
129 -
      wrapDecodingOperation(() => _decodedValue.asList());
122 +
      wrapJsonUtilOperation(() => _decodedValue.asList());
130 123
131 124
  // <<decoding methods>>
132 125
@@ -135,7 +128,7 @@
Loading
135 128
  /// The JSON data must be a JSON primitive value and [T] must be a primitive
136 129
  ///  type (int, double, bool or String) or it will throw a [JsonDecodingError].
137 130
  T decodeAsPrimitiveValue<T>() =>
138 -
      wrapDecodingOperation(() => _decodedValue.asPrimitiveValue<T>());
131 +
      wrapJsonUtilOperation(() => _decodedValue.asPrimitiveValue<T>());
139 132
140 133
  /// Returns the JSON data decoded as an instance of [List<T>].
141 134
  ///
@@ -143,14 +136,14 @@
Loading
143 136
  /// be a primitive type (int, double, bool or String) or it will throw
144 137
  /// a [JsonDecodingError].
145 138
  List<T> decodeAsPrimitiveList<T>() =>
146 -
      wrapDecodingOperation(() => _decodedValue.asPrimitiveList<T>());
139 +
      wrapJsonUtilOperation(() => _decodedValue.asPrimitiveList<T>());
147 140
148 141
  /// Returns the JSON data decoded as an instance of [T extends Object].
149 142
  ///
150 143
  /// The JSON data must be a JSON object or it will throw
151 144
  /// a [JsonDecodingError].
152 145
  T decodeAsObject<T extends Object>(JsonObjectDecoder<T> decoder) =>
153 -
      wrapDecodingOperation(
146 +
      wrapJsonUtilOperation(
154 147
          () => _decodedValue.asObject(decoder, skipIfNull: true));
155 148
156 149
  /// Returns the JSON data decoded as an instance of [List<T extends Object>].
@@ -158,7 +151,7 @@
Loading
158 151
  /// The JSON data must be a list of JSON objects or it
159 152
  /// will throw a [JsonDecodingError].
160 153
  List<T> decodeAsObjectList<T extends Object>(JsonObjectDecoder<T> decoder) =>
161 -
      wrapDecodingOperation(
154 +
      wrapJsonUtilOperation(
162 155
          () => _decodedValue.asObjectList(decoder, skipNullValues: true));
163 156
164 157
  // <<standard methods>>
@@ -183,12 +176,12 @@
Loading
183 176
  final DecodedValue _cachedValue;
184 177
185 178
  DecodedValue get _decodedValue =>
186 -
      (_cachedValue != null) ? _cachedValue : _getDecodedValue(this.source);
179 +
      (_cachedValue != null) ? _cachedValue : DecodedValue.from(this.source);
187 180
188 181
  // <<private methods>>
189 182
190 183
  static JsonString _constructJsonString(String source, bool enableCache) {
191 -
    final decodedSource = _getDecodedValue(source);
184 +
    final decodedSource = DecodedValue.from(source);
192 185
    final cachedValue = enableCache ? decodedSource : null;
193 186
    return JsonString._(_encode(decodedSource.value), cachedValue);
194 187
  }
@@ -207,13 +200,4 @@
Loading
207 200
      throw JsonEncodingError(e);
208 201
    }
209 202
  }
210 -
211 -
  static DecodedValue _getDecodedValue(String source) {
212 -
    assert(source != null);
213 -
    try {
214 -
      return DecodedValue.from(source);
215 -
    } catch (e) {
216 -
      throw JsonDecodingError(e);
217 -
    }
218 -
  }
219 203
}

@@ -29,18 +29,12 @@
Loading
29 29
  return jsonObject as Map<String, dynamic>;
30 30
}
31 31
32 -
T wrapDecodingOperation<T>(T exec()) {
32 +
T wrapJsonUtilOperation<T>(T exec()) {
33 33
  try {
34 34
    return exec();
35 -
  } on JsonUtilError catch (e) {
35 +
  } on DecodedValueError catch (e) {
36 36
    throw JsonDecodingError(e);
37 -
  }
38 -
}
39 -
40 -
T wrapEncodingOperation<T>(T exec()) {
41 -
  try {
42 -
    return exec();
43 -
  } on JsonUtilError catch (e) {
37 +
  } on EncodableValueError catch (e) {
44 38
    throw JsonEncodingError(e);
45 39
  }
46 40
}
Files Coverage
lib/src 100.00%
Project Totals (3 files) 100.00%
Untitled

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading