├── angel_serialize
├── mono_pkg.yaml
├── analysis_options.yaml
├── README.md
├── example
│ └── main.dart
├── pubspec.yaml
├── CHANGELOG.md
├── LICENSE
├── .gitignore
└── lib
│ └── angel_serialize.dart
├── angel_serialize_generator
├── mono_pkg.yaml
├── README.md
├── analysis_options.yaml
├── example
│ ├── main.dart
│ └── main.g.dart
├── test
│ ├── models
│ │ ├── goat.dart
│ │ ├── game_pad_button.dart
│ │ ├── with_enum.dart
│ │ ├── subclass.dart
│ │ ├── has_map.dart
│ │ ├── book.d.ts
│ │ ├── book.dart
│ │ ├── goat.g.dart
│ │ ├── has_map.g.dart
│ │ ├── with_enum.g.dart
│ │ ├── game_pad_button.g.dart
│ │ ├── subclass.g.dart
│ │ └── book.g.dart
│ ├── serializer_test.dart
│ ├── default_value_test.dart
│ ├── enum_test.dart
│ └── book_test.dart
├── pubspec.yaml
├── LICENSE
├── build.yaml
├── .gitignore
├── lib
│ ├── context.dart
│ ├── angel_serialize_generator.dart
│ ├── typescript.dart
│ ├── build_context.dart
│ ├── model.dart
│ └── serialize.dart
└── CHANGELOG.md
├── .travis.yml
├── tool
└── .travis.sh
├── .idea
├── vcs.xml
├── modules.xml
├── runConfigurations
│ ├── tests_in_enum_test_dart.xml
│ └── tests_in_angel_serialize_generator.xml
└── serialize.iml
├── .gitignore
└── README.md
/angel_serialize/mono_pkg.yaml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/angel_serialize_generator/mono_pkg.yaml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: dart
2 | script: bash tool/.travis.sh
3 | dart:
4 | - stable
--------------------------------------------------------------------------------
/tool/.travis.sh:
--------------------------------------------------------------------------------
1 | cd angel_serialize_generator
2 | pub get
3 | pub run build_runner build --delete-conflicting-outputs
4 | pub run test
--------------------------------------------------------------------------------
/angel_serialize/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | include: package:pedantic/analysis_options.yaml
2 | analyzer:
3 | strong-mode:
4 | implicit-casts: false
--------------------------------------------------------------------------------
/angel_serialize/README.md:
--------------------------------------------------------------------------------
1 | # angel_serialize
2 | The frontend for Angel model serialization.
3 | See documentation in the main project repo:
4 |
5 | https://github.com/angel-dart/serialize
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/angel_serialize_generator/README.md:
--------------------------------------------------------------------------------
1 | # angel_serialize_generator
2 | The builder for Angel's model serialization.
3 |
4 | Find documentation in the main project repo:
5 | https://github.com/angel-dart/serialize
--------------------------------------------------------------------------------
/angel_serialize/example/main.dart:
--------------------------------------------------------------------------------
1 | // ignore_for_file: unused_element
2 | import 'package:angel_serialize/angel_serialize.dart';
3 |
4 | @serializable
5 | class _Todo {
6 | String text;
7 | bool completed;
8 | }
9 |
--------------------------------------------------------------------------------
/angel_serialize_generator/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | include: package:pedantic/analysis_options.yaml
2 | analyzer:
3 | strong-mode:
4 | implicit-casts: false
5 | linter:
6 | rules:
7 | - unnecessary_new
8 | - unnecessary_const
--------------------------------------------------------------------------------
/angel_serialize_generator/example/main.dart:
--------------------------------------------------------------------------------
1 | // ignore_for_file: unused_element
2 | import 'package:angel_serialize/angel_serialize.dart';
3 | part 'main.g.dart';
4 |
5 | @serializable
6 | class _Todo {
7 | String text;
8 | bool completed;
9 | }
10 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/angel_serialize_generator/test/models/goat.dart:
--------------------------------------------------------------------------------
1 | import 'package:angel_serialize/angel_serialize.dart';
2 | import 'package:collection/collection.dart';
3 | part 'goat.g.dart';
4 |
5 | @serializable
6 | abstract class _Goat {
7 | @SerializableField(defaultValue: 34)
8 | int get integer;
9 |
10 | @SerializableField(defaultValue: [34, 35])
11 | List get list;
12 | }
13 |
--------------------------------------------------------------------------------
/angel_serialize_generator/test/models/game_pad_button.dart:
--------------------------------------------------------------------------------
1 | import 'package:angel_serialize/angel_serialize.dart';
2 | part 'game_pad_button.g.dart';
3 |
4 | @serializable
5 | abstract class _GamepadButton {
6 | String get name;
7 | int get radius;
8 | }
9 |
10 | @serializable
11 | class _Gamepad {
12 | List<_GamepadButton> buttons;
13 |
14 | Map dynamicMap;
15 |
16 | // ignore: unused_field
17 | String _somethingPrivate;
18 | }
19 |
--------------------------------------------------------------------------------
/.idea/runConfigurations/tests_in_enum_test_dart.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/angel_serialize_generator/test/models/with_enum.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 | import 'dart:typed_data';
3 | import 'package:angel_serialize/angel_serialize.dart';
4 | import 'package:collection/collection.dart';
5 | part 'with_enum.g.dart';
6 |
7 | @serializable
8 | abstract class _WithEnum {
9 | @DefaultsTo(WithEnumType.b)
10 | WithEnumType get type;
11 |
12 | List get finalList;
13 |
14 | Uint8List get imageBytes;
15 | }
16 |
17 | enum WithEnumType { a, b, c }
18 |
--------------------------------------------------------------------------------
/angel_serialize/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: angel_serialize
2 | version: 2.2.3+3
3 | description: Static annotations powering Angel model serialization. Combine with angel_serialize_generator for flexible modeling.
4 | author: Tobe O
5 | homepage: https://github.com/angel-dart/serialize
6 | environment:
7 | sdk: '>=2.0.0-dev <3.0.0'
8 | dependencies:
9 | angel_model: ^1.0.0
10 | collection: ^1.0.0
11 | meta: ^1.0.0
12 | pedantic: ^1.0.0
13 | quiver_hashcode: ^2.0.0
14 |
--------------------------------------------------------------------------------
/angel_serialize_generator/test/models/subclass.dart:
--------------------------------------------------------------------------------
1 | import 'package:angel_serialize/angel_serialize.dart';
2 | part 'subclass.g.dart';
3 |
4 | @serializable
5 | class _Animal {
6 | @notNull
7 | String genus;
8 | @notNull
9 | String species;
10 | }
11 |
12 | @serializable
13 | class _Bird extends _Animal {
14 | @DefaultsTo(false)
15 | bool isSparrow;
16 | }
17 |
18 | var saxaulSparrow = Bird(
19 | genus: 'Passer',
20 | species: 'ammodendri',
21 | isSparrow: true,
22 | );
23 |
--------------------------------------------------------------------------------
/.idea/runConfigurations/tests_in_angel_serialize_generator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/angel_serialize_generator/test/serializer_test.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 | import 'package:test/test.dart';
3 | import 'models/has_map.dart';
4 |
5 | void main() {
6 | var m = HasMap(value: {'foo': 'bar'});
7 | print(json.encode(m));
8 |
9 | test('json', () {
10 | expect(json.encode(m), r'{"value":"{\"foo\":\"bar\"}"}');
11 | });
12 |
13 | test('decode', () {
14 | var mm = json.decode(r'{"value":"{\"foo\":\"bar\"}"}') as Map;
15 | var mmm = HasMapSerializer.fromMap(mm);
16 | expect(mmm, m);
17 | });
18 | }
19 |
--------------------------------------------------------------------------------
/angel_serialize_generator/test/models/has_map.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 | import 'package:angel_serialize/angel_serialize.dart';
3 | import 'package:collection/collection.dart';
4 | import 'package:meta/meta.dart';
5 | part 'has_map.g.dart';
6 |
7 | Map _fromString(v) => json.decode(v.toString()) as Map;
8 |
9 | String _toString(Map v) => json.encode(v);
10 |
11 | @serializable
12 | abstract class _HasMap {
13 | @SerializableField(
14 | serializer: #_toString,
15 | deserializer: #_fromString,
16 | isNullable: false,
17 | serializesTo: String)
18 | Map get value;
19 | }
20 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | .idea/**/workspace.xml
3 | .idea/**/tasks.xml
4 | .idea/dictionaries
5 | .idea/**/dataSources/
6 | .idea/**/dataSources.ids
7 | .idea/**/dataSources.xml
8 | .idea/**/dataSources.local.xml
9 | .idea/**/sqlDataSources.xml
10 | .idea/**/dynamic.xml
11 | .idea/**/uiDesigner.xml
12 | .idea/**/gradle.xml
13 | .idea/**/libraries
14 | .idea/**/mongoSettings.xml
15 | *.iws
16 | /out/
17 | .idea_modules/
18 | atlassian-ide-plugin.xml
19 | com_crashlytics_export_strings.xml
20 | crashlytics.properties
21 | crashlytics-build.properties
22 | fabric.properties
23 | .dart_tool
--------------------------------------------------------------------------------
/angel_serialize_generator/test/default_value_test.dart:
--------------------------------------------------------------------------------
1 | import 'package:test/test.dart';
2 | import 'models/goat.dart';
3 |
4 | void main() {
5 | group('constructor', () {
6 | test('int default', () {
7 | expect(Goat().integer, 34);
8 | });
9 |
10 | test('list default', () {
11 | expect(Goat().list, [34, 35]);
12 | });
13 | });
14 |
15 | group('from map', () {
16 | test('int default', () {
17 | expect(GoatSerializer.fromMap({}).integer, 34);
18 | });
19 |
20 | test('list default', () {
21 | expect(GoatSerializer.fromMap({}).list, [34, 35]);
22 | });
23 | });
24 | }
25 |
--------------------------------------------------------------------------------
/angel_serialize_generator/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: angel_serialize_generator
2 | version: 2.5.0
3 | description: Model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling.
4 | author: Tobe O
5 | homepage: https://github.com/angel-dart/serialize
6 | environment:
7 | sdk: '>=2.0.0 <3.0.0'
8 | dependencies:
9 | analyzer: ">=0.27.1 <2.0.0"
10 | angel_model: ^1.0.0
11 | angel_serialize: ^2.2.0
12 | build: ">=0.12.0 <2.0.0"
13 | build_config: ">=0.3.0 <2.0.0"
14 | code_buffer: ^1.0.0
15 | code_builder: ^3.0.0
16 | meta: ^1.0.0
17 | path: ^1.0.0
18 | recase: ^2.0.0
19 | source_gen: ^0.9.0
20 | quiver: ^2.0.0
21 | dev_dependencies:
22 | build_runner: ^1.0.0
23 | collection: ^1.0.0
24 | pedantic: ^1.0.0
25 | test: ^1.0.0
26 | # dependency_overrides:
27 | # angel_serialize:
28 | # path: ../angel_serialize
--------------------------------------------------------------------------------
/angel_serialize_generator/test/models/book.d.ts:
--------------------------------------------------------------------------------
1 | // GENERATED CODE - DO NOT MODIFY BY HAND
2 | declare module 'angel_serialize_generator' {
3 | interface Book {
4 | id?: string;
5 | created_at?: any;
6 | updated_at?: any;
7 | author?: string;
8 | title?: string;
9 | description?: string;
10 | page_count?: number;
11 | not_models?: number[];
12 | camelCase?: string;
13 | }
14 | interface Author {
15 | id?: string;
16 | created_at?: any;
17 | updated_at?: any;
18 | name: string;
19 | age: number;
20 | books?: Book[];
21 | newest_book?: Book;
22 | }
23 | interface Library {
24 | id?: string;
25 | created_at?: any;
26 | updated_at?: any;
27 | collection?: LibraryCollection;
28 | }
29 | interface LibraryCollection {
30 | [key: string]: Book;
31 | }
32 | interface Bookmark {
33 | id?: string;
34 | created_at?: any;
35 | updated_at?: any;
36 | history?: number[];
37 | page: number;
38 | comment?: string;
39 | }
40 | }
--------------------------------------------------------------------------------
/angel_serialize/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # 2.2.3+3
2 | * Add `exclude: true` to `super` call in `Exclude` constructor.
3 |
4 | # 2.2.3+2
5 | * Apply `package:pedantic`.
6 |
7 | # 2.2.3+1
8 | * Export `json`, `Codec`, and `Converter` from `dart:convert`.
9 |
10 | # 2.2.3
11 | * `isNullable` defaults to `true`, and will not change.
12 | * Deprecate `@nullable`.
13 | * Add `@notNull`.
14 |
15 | # 2.2.2+1
16 | * Export commonly-used packages, for the sake of convenience.
17 |
18 | # 2.2.2
19 | * Add `HasAlias`, `DefaultsTo`, `nullable` idioms.
20 | * `isNullable` defaults to `false` now.
21 |
22 | # 2.2.1
23 | * Add `serializesTo`.
24 |
25 | # 2.2.0
26 | * Add `@SerializableField`.
27 |
28 | # 2.1.0
29 | * Export `hashObjects`.
30 |
31 | # 2.0.4+1
32 | * Allow Dart 1 for this annotation-only package.
33 |
34 | # 2.0.4
35 | * Added `generatedSerializable`.
36 |
37 | # 2.0.3
38 | * Increased the upper SDK boundary.
39 |
40 | # 2.0.2
41 | * Added `DefaultValue`.
42 |
43 | # 2.0.1
44 | * Added `Serializers.typescript`.
45 |
46 | # 2.0.0
47 | * Dart 2+ constraint
48 |
--------------------------------------------------------------------------------
/.idea/serialize.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/angel_serialize/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 The Angel Framework
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/angel_serialize_generator/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 The Angel Framework
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/angel_serialize_generator/build.yaml:
--------------------------------------------------------------------------------
1 | builders:
2 | angel_serialize:
3 | import: "package:angel_serialize_generator/angel_serialize_generator.dart"
4 | builder_factories:
5 | - jsonModelBuilder
6 | - serializerBuilder
7 | auto_apply: root_package
8 | build_to: cache
9 | build_extensions:
10 | .dart:
11 | - ".angel_serialize.g.part"
12 | - ".angel_serialize_serializer.g.part"
13 | applies_builders: ["source_gen|combining_builder", "source_gen|part_cleanup"]
14 | runs_before: ["angel_orm_generator|angel_orm"]
15 | typescript:
16 | import: "package:angel_serialize_generator/angel_serialize_generator.dart"
17 | builder_factories:
18 | - typescriptDefinitionBuilder
19 | auto_apply: root_package
20 | build_to: source
21 | build_extensions:
22 | .dart:
23 | - ".d.ts"
24 | # targets:
25 | # _book:
26 | # sources:
27 | # - "test/models/book.dart"
28 | # - "test/models/has_map.dart"
29 | # - "test/models/goat.dart"
30 | # - "test/models/game_pad_button.dart"
31 | # - "test/models/with_enum.dart"
32 | # $default:
33 | # dependencies:
34 | # - "angel_serialize_generator:_book"
35 | # sources:
36 | # - "test/models/author.dart"
37 | # - "test/models/game_pad.dart"
38 |
--------------------------------------------------------------------------------
/angel_serialize/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://www.dartlang.org/tools/private-files.html
2 |
3 | # Files and directories created by pub
4 | ../.packages
5 | .packages
6 | .pub/
7 | build/
8 | # If you're building an application, you may want to check-in your pubspec.lock
9 | pubspec.lock
10 |
11 | # Directory created by dartdoc
12 | # If you don't generate documentation locally you can remove this line.
13 | doc/api/
14 | ### JetBrains template
15 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
16 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
17 |
18 | # User-specific stuff:
19 | .idea/**/workspace.xml
20 | .idea/**/tasks.xml
21 | .idea/dictionaries
22 |
23 | # Sensitive or high-churn files:
24 | .idea/**/dataSources/
25 | .idea/**/dataSources.ids
26 | .idea/**/dataSources.xml
27 | .idea/**/dataSources.local.xml
28 | .idea/**/sqlDataSources.xml
29 | .idea/**/dynamic.xml
30 | .idea/**/uiDesigner.xml
31 |
32 | # Gradle:
33 | .idea/**/gradle.xml
34 | .idea/**/libraries
35 |
36 | # Mongo Explorer plugin:
37 | .idea/**/mongoSettings.xml
38 |
39 | ## File-based project format:
40 | *.iws
41 |
42 | ## Plugin-specific files:
43 |
44 | # IntelliJ
45 | /out/
46 |
47 | # mpeltonen/sbt-idea plugin
48 | .idea_modules/
49 |
50 | # JIRA plugin
51 | atlassian-ide-plugin.xml
52 |
53 | # Crashlytics plugin (for Android Studio and IntelliJ)
54 | com_crashlytics_export_strings.xml
55 | crashlytics.properties
56 | crashlytics-build.properties
57 | fabric.properties
58 |
--------------------------------------------------------------------------------
/angel_serialize_generator/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://www.dartlang.org/tools/private-files.html
2 |
3 | # Files and directories created by pub
4 | .packages
5 | .pub/
6 | build/
7 | # If you're building an application, you may want to check-in your pubspec.lock
8 | pubspec.lock
9 |
10 | # Directory created by dartdoc
11 | # If you don't generate documentation locally you can remove this line.
12 | doc/api/
13 | ### JetBrains template
14 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
15 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
16 |
17 | # User-specific stuff:
18 | .idea/**/workspace.xml
19 | .idea/**/tasks.xml
20 | .idea/dictionaries
21 |
22 | # Sensitive or high-churn files:
23 | .idea/**/dataSources/
24 | .idea/**/dataSources.ids
25 | .idea/**/dataSources.xml
26 | .idea/**/dataSources.local.xml
27 | .idea/**/sqlDataSources.xml
28 | .idea/**/dynamic.xml
29 | .idea/**/uiDesigner.xml
30 |
31 | # Gradle:
32 | .idea/**/gradle.xml
33 | .idea/**/libraries
34 |
35 | # Mongo Explorer plugin:
36 | .idea/**/mongoSettings.xml
37 |
38 | ## File-based project format:
39 | *.iws
40 |
41 | ## Plugin-specific files:
42 |
43 | # IntelliJ
44 | /out/
45 |
46 | # mpeltonen/sbt-idea plugin
47 | .idea_modules/
48 |
49 | # JIRA plugin
50 | atlassian-ide-plugin.xml
51 |
52 | # Crashlytics plugin (for Android Studio and IntelliJ)
53 | com_crashlytics_export_strings.xml
54 | crashlytics.properties
55 | crashlytics-build.properties
56 | fabric.properties
57 |
58 | *.g.part
--------------------------------------------------------------------------------
/angel_serialize_generator/test/models/book.dart:
--------------------------------------------------------------------------------
1 | library angel_serialize.test.models.book;
2 |
3 | import 'package:angel_model/angel_model.dart';
4 | import 'package:angel_serialize/angel_serialize.dart';
5 | import 'package:collection/collection.dart';
6 | import 'package:meta/meta.dart';
7 | part 'book.g.dart';
8 |
9 | @Serializable(
10 | serializers: Serializers.all,
11 | includeAnnotations: [
12 | pragma('hello'),
13 | SerializableField(alias: 'omg'),
14 | ],
15 | )
16 | abstract class _Book extends Model {
17 | String author, title, description;
18 |
19 | /// The number of pages the book has.
20 | int pageCount;
21 |
22 | List notModels;
23 |
24 | @SerializableField(alias: 'camelCase', isNullable: true)
25 | String camelCaseString;
26 | }
27 |
28 | @Serializable(serializers: Serializers.all)
29 | abstract class _Author extends Model {
30 | @SerializableField(isNullable: false)
31 | String get name;
32 |
33 | String get customMethod => 'hey!';
34 |
35 | @SerializableField(
36 | isNullable: false, errorMessage: 'Custom message for missing `age`')
37 | int get age;
38 |
39 | List<_Book> get books;
40 |
41 | /// The newest book.
42 | _Book get newestBook;
43 |
44 | @SerializableField(exclude: true, isNullable: true)
45 | String get secret;
46 |
47 | @SerializableField(exclude: true, canDeserialize: true, isNullable: true)
48 | String get obscured;
49 | }
50 |
51 | @Serializable(serializers: Serializers.all)
52 | abstract class _Library extends Model {
53 | Map get collection;
54 | }
55 |
56 | @Serializable(serializers: Serializers.all)
57 | abstract class _Bookmark extends Model {
58 | @SerializableField(exclude: true)
59 | final _Book book;
60 |
61 | List get history;
62 |
63 | @SerializableField(isNullable: false)
64 | int get page;
65 |
66 | String get comment;
67 |
68 | _Bookmark(this.book);
69 | }
70 |
--------------------------------------------------------------------------------
/angel_serialize_generator/test/enum_test.dart:
--------------------------------------------------------------------------------
1 | import 'dart:typed_data';
2 |
3 | import 'package:test/test.dart';
4 | import 'models/with_enum.dart';
5 |
6 | const WithEnum aWithEnum = WithEnum(type: WithEnumType.a);
7 | const WithEnum aWithEnum2 = WithEnum(type: WithEnumType.a);
8 |
9 | void main() {
10 | test('enum serializes to int', () {
11 | var w = WithEnum(type: WithEnumType.b).toJson();
12 | expect(w[WithEnumFields.type], WithEnumType.values.indexOf(WithEnumType.b));
13 | });
14 |
15 | test('enum serializes null if null', () {
16 | var w = WithEnum(type: null).toJson();
17 | expect(w[WithEnumFields.type], null);
18 | });
19 |
20 | test('enum deserializes to default value from null', () {
21 | var map = {WithEnumFields.type: null};
22 | var w = WithEnumSerializer.fromMap(map);
23 | expect(w.type, WithEnumType.b);
24 | });
25 |
26 | test('enum deserializes from int', () {
27 | var map = {
28 | WithEnumFields.type: WithEnumType.values.indexOf(WithEnumType.b)
29 | };
30 | var w = WithEnumSerializer.fromMap(map);
31 | expect(w.type, WithEnumType.b);
32 | });
33 |
34 | test('enum deserializes from value', () {
35 | var map = {WithEnumFields.type: WithEnumType.c};
36 | var w = WithEnumSerializer.fromMap(map);
37 | expect(w.type, WithEnumType.c);
38 | });
39 |
40 | test('equality', () {
41 | expect(WithEnum(type: WithEnumType.a), WithEnum(type: WithEnumType.a));
42 | expect(
43 | WithEnum(type: WithEnumType.a), isNot(WithEnum(type: WithEnumType.b)));
44 | });
45 |
46 | test('const', () {
47 | expect(identical(aWithEnum, aWithEnum2), true);
48 | });
49 |
50 | test('uint8list', () {
51 | var ee = WithEnum(
52 | imageBytes: Uint8List.fromList(List.generate(1000, (i) => i)));
53 | var eeMap = ee.toJson();
54 | print(ee);
55 | var ef = WithEnumSerializer.fromMap(eeMap);
56 | expect(ee.copyWith(), ee);
57 | expect(ef, ee);
58 | });
59 | }
60 |
--------------------------------------------------------------------------------
/angel_serialize_generator/example/main.g.dart:
--------------------------------------------------------------------------------
1 | // GENERATED CODE - DO NOT MODIFY BY HAND
2 |
3 | part of 'main.dart';
4 |
5 | // **************************************************************************
6 | // JsonModelGenerator
7 | // **************************************************************************
8 |
9 | @generatedSerializable
10 | class Todo extends _Todo {
11 | Todo({this.text, this.completed});
12 |
13 | @override
14 | String text;
15 |
16 | @override
17 | bool completed;
18 |
19 | Todo copyWith({String text, bool completed}) {
20 | return Todo(
21 | text: text ?? this.text, completed: completed ?? this.completed);
22 | }
23 |
24 | bool operator ==(other) {
25 | return other is _Todo && other.text == text && other.completed == completed;
26 | }
27 |
28 | @override
29 | int get hashCode {
30 | return hashObjects([text, completed]);
31 | }
32 |
33 | @override
34 | String toString() {
35 | return "Todo(text=$text, completed=$completed)";
36 | }
37 |
38 | Map toJson() {
39 | return TodoSerializer.toMap(this);
40 | }
41 | }
42 |
43 | // **************************************************************************
44 | // SerializerGenerator
45 | // **************************************************************************
46 |
47 | const TodoSerializer todoSerializer = TodoSerializer();
48 |
49 | class TodoEncoder extends Converter {
50 | const TodoEncoder();
51 |
52 | @override
53 | Map convert(Todo model) => TodoSerializer.toMap(model);
54 | }
55 |
56 | class TodoDecoder extends Converter