Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #29 from davidmorgan/fix-maps
Browse files Browse the repository at this point in the history
Fix issue with BuiltMap deserialization. Add test.
  • Loading branch information
davidmorgan authored Sep 12, 2016
2 parents 4781829 + 7f7ae86 commit 37c5781
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.1.2

- Fix issue with BuiltMap deserialization.

## 0.1.1

- Fix error in pubspec.yaml.
Expand Down
2 changes: 1 addition & 1 deletion built_json/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: built_json
version: 0.1.1
version: 0.1.2
description: >
JSON serialization for Built Collections, Built Values and Enum Classes.
This library is the runtime dependency.
Expand Down
2 changes: 1 addition & 1 deletion built_json_generator/lib/src/source_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class SourceField implements Built<SourceField, SourceFieldBuilder> {
static final BuiltMap<String, String> typesWithBuilder =
new BuiltMap<String, String>({
'BuiltList': 'ListBuilder',
'BuiltMap': 'MapBuiler',
'BuiltMap': 'MapBuilder',
'BuiltSet': 'SetBuilder',
});

Expand Down
4 changes: 2 additions & 2 deletions built_json_generator/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: built_json_generator
version: 0.1.1
version: 0.1.2
description: >
JSON serialization for Built Collections, Built Values and Enum Classes.
This library is the dev dependency.
Expand All @@ -14,7 +14,7 @@ dependencies:
analyzer: '>=0.27.1 <0.28.0'
build: '^0.3.0'
built_collection: '^1.0.1'
built_json: '^0.1.0'
built_json: '^0.1.2'
source_gen: '>=0.5.0 <0.6.0'
quiver: '>=0.21.0 <0.22.0'

Expand Down
40 changes: 40 additions & 0 deletions example/lib/collections.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2016, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

library collections;

import 'package:built_collection/built_collection.dart';
import 'package:built_json/built_json.dart';
import 'package:built_value/built_value.dart';

part 'collections.g.dart';

/// Example built_value type containing collections.
abstract class Collections
implements Built<Collections, CollectionsBuilder> {
/// Example of how to make a built_value type serializable.
///
/// Declare a static final [Serializers] field called `serializer`.
/// The built_json code generator will provide the implementation. You need to
/// do this for every type you want to serialize.
static final Serializer<Collections> serializer = _$collectionsSerializer;

BuiltList<String> get list;
BuiltSet<int> get set;
BuiltMap<String, int> get map;

Collections._();
factory Collections([updates(CollectionsBuilder b)]) = _$Collections;
}

/// Builder class for [Collections].
abstract class CollectionsBuilder
implements Builder<Collections, CollectionsBuilder> {
ListBuilder<String> list = new ListBuilder<String>();
SetBuilder<int> set = new SetBuilder<int>();
MapBuilder<String, int> map = new MapBuilder<String, int>();

CollectionsBuilder._();
factory CollectionsBuilder() = _$CollectionsBuilder;
}
133 changes: 133 additions & 0 deletions example/lib/collections.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions example/lib/has_int.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions example/lib/serializers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ library serializers;

import 'package:built_collection/built_collection.dart';
import 'package:built_json/built_json.dart';
import 'package:example/collections.dart';
import 'package:example/compound_value.dart';
import 'package:example/has_int.dart';
import 'package:example/test_enum.dart';
Expand Down
10 changes: 10 additions & 0 deletions example/lib/serializers.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions example/lib/test_enum.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: example
version: 0.1.0
version: 0.1.2
description: >
Just an example, not for publishing.
authors:
Expand All @@ -11,12 +11,12 @@ environment:

dependencies:
built_collection: '^1.0.0'
built_json: '^0.1.0'
built_json: '^0.1.2'
built_value: '^0.1.0'
enum_class: '^0.1.0'

dev_dependencies:
built_json_generator: '^0.1.0'
built_json_generator: '^0.1.2'
built_value_generator: '^0.1.0'
enum_class_generator: '^0.1.0'
test: any
34 changes: 34 additions & 0 deletions example/test/collections_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2016, Google Inc. Please see the AUTHORS file for details.

// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

import 'package:example/collections.dart';
import 'package:example/serializers.dart';
import 'package:test/test.dart';

void main() {
group('Collections', () {
final data = new Collections((b) => b
..list.add('one')
..set.add(2)
..map['three'] = 4);
final serialized = [
'Collections',
'list',
['one'],
'set',
[2],
'map',
['three', 4],
];

test('can be serialized', () {
expect(serializers.serialize(data), serialized);
});

test('can be deserialized', () {
expect(serializers.deserialize(serialized), data);
});
});
}

0 comments on commit 37c5781

Please sign in to comment.