This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:json_annotation/json_annotation.dart'; | |
| @JsonSerializable | |
| class SimpleObject { | |
| ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:json_annotation/json_annotation.dart'; | |
| part 'simple_object.g.dart'; | |
| @JsonSerializable() | |
| class SimpleObject extends Object with _$SimpleObjectSerializerMixin { | |
| SimpleObject({ | |
| this.aString, | |
| this.anInt, | |
| this.aDouble, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| part of 'simple_object.dart'; | |
| SimpleObject _$SimpleObjectFromJson( | |
| Map<String, dynamic> json) => | |
| new SimpleObject( | |
| aString: json['aString'] as String, | |
| anInt: json['anInt'] as int, | |
| aDouble: (json['aDouble'] as num)?.toDouble(), | |
| aListOfStrings: | |
| (json['aListOfStrings'] as List)?.map((e) => e as String)?.toList(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final myObject = SimpleObject.fromJson(json.decode(jsonString)); | |
| final myJsonStr = json.encode(myObject.toJson()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:built_collection/built_collection.dart'; | |
| import 'package:built_value/built_value.dart'; | |
| import 'package:built_value/serializer.dart'; | |
| part 'simple_object.g.dart'; | |
| abstract class SimpleObject | |
| implements Built<SimpleObject, SimpleObjectBuilder> { | |
| static Serializer<SimpleObject> get serializer => | |
| _$SimpleObjectSerializer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final SimpleObject myObject = SimpleObject((b) => b | |
| ..aString = 'Blah, blah, blah' | |
| ..anInt = 1 | |
| ..aDouble = 1.0 | |
| ..aListOfStrings = ListBuilder<String>(['one', 'two', 'three']) | |
| ..aListOfInts = ListBuilder<int>([1, 2, 3]) | |
| ..aListOfDoubles = ListBuilder<double>([1.0, 2.0, 3.0]) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final SimpleObject anotherObject = myObject.rebuild((b) => b | |
| ..aString = "An updated value" | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SimpleObject._(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:built_collection/built_collection.dart'; | |
| import 'package:built_value/serializer.dart'; | |
| import 'package:built_value/standard_json_plugin.dart'; | |
| import 'simple_object.dart'; | |
| part 'serializers.g.dart'; | |
| @SerializersFor(const [ | |
| SimpleObject, | |
| ]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final myObject = serializers.deserializeWith( | |
| SimpleObject.serializer, json.decode(aJsonString)); | |
| final String myJsonString = json.encode(serializers.serialize(myObject)); |