You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+50
Original file line number
Diff line number
Diff line change
@@ -231,6 +231,56 @@ OR use it individually on selected class fields, via `@JsonProperty` annotation
231
231
String title;
232
232
```
233
233
234
+
## Typenamehandling
235
+
236
+
With setting the `includeTypeName` property to `true`_dart-json-mapper_ will dump the object type to the JSON output. This ensures, that _dart-json-mapper_ can reconstruct the object with the right type when deserializing.
237
+
238
+
```dart
239
+
@jsonSerializable
240
+
abstract class Business {
241
+
String name;
242
+
}
243
+
244
+
@JsonSerializable(includeTypeName: true)
245
+
class Hotel extends Business {
246
+
int stars;
247
+
248
+
Hotel(this.stars);
249
+
}
250
+
251
+
@JsonSerializable(includeTypeName: true)
252
+
class Startup extends Business {
253
+
int userCount;
254
+
255
+
Startup(this.userCount);
256
+
}
257
+
258
+
@jsonSerializable
259
+
class Stakeholder {
260
+
String fullName;
261
+
List<Business> businesses;
262
+
263
+
Stakeholder(this.fullName, this.businesses);
264
+
}
265
+
266
+
final jack = Stakeholder("Jack", [Startup(10), Hotel(4)]);
267
+
268
+
final iterableBusinessDecorator = (value) => value.cast<Business>();
0 commit comments