2.0.8, frozen

This commit is contained in:
Tobe O 2018-06-23 00:52:46 -04:00
parent 4511a14ea4
commit 403e2e600e
7 changed files with 31 additions and 12 deletions

View file

@ -2,10 +2,12 @@
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$/angel_serialize">
<excludeFolder url="file://$MODULE_DIR$/angel_serialize/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/angel_serialize/.pub" />
<excludeFolder url="file://$MODULE_DIR$/angel_serialize/build" />
</content>
<content url="file://$MODULE_DIR$/angel_serialize_generator">
<excludeFolder url="file://$MODULE_DIR$/angel_serialize_generator/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/angel_serialize_generator/.pub" />
<excludeFolder url="file://$MODULE_DIR$/angel_serialize_generator/build" />
</content>

View file

@ -1,3 +1,6 @@
# 2.0.8
* Generate a `fromMap` with typecasting, for Dart 2's sake.
# 2.0.7
* Create unmodifiable Lists and Maps.
* Support `@required` on fields.

View file

@ -79,3 +79,16 @@ bool isMapToModelType(InterfaceType t) {
t.typeArguments.length == 2 &&
isModelClass(t.typeArguments[1]);
}
/// Compute a [String] representation of a [type].
String typeToString(DartType type) {
if (type is InterfaceType) {
if (type.typeArguments.isEmpty) return type.name;
return type.name +
'<' +
type.typeArguments.map(typeToString).join(', ') +
'>';
} else {
return type.name;
}
}

View file

@ -172,12 +172,13 @@ class SerializerGenerator extends GeneratorForAnnotation<Serializable> {
if (i++ > 0) buf.write(', ');
String deserializedRepresentation = "map['$alias']";
String deserializedRepresentation = "map['$alias'] as ${typeToString(
field.type)}";
// Deserialize dates
if (dateTimeTypeChecker.isAssignableFromType(field.type))
deserializedRepresentation = "map['$alias'] != null ? "
"(map['$alias'] is DateTime ? map['$alias'] : DateTime.parse(map['$alias']))"
"(map['$alias'] is DateTime ? (map['$alias'] as DateTime) : DateTime.parse(map['$alias']))"
" : null";
// Serialize model classes via `XSerializer.toMap`
@ -192,16 +193,16 @@ class SerializerGenerator extends GeneratorForAnnotation<Serializable> {
if (isListModelType(t)) {
var rc = new ReCase(t.typeArguments[0].name);
deserializedRepresentation = "map['$alias'] is Iterable"
" ? new List.unmodifiable(map['$alias'].map(${rc
" ? new List.unmodifiable((map['$alias'] as Iterable).whereType<Map>().map(${rc
.pascalCase}Serializer.fromMap))"
" : null";
} else if (isMapToModelType(t)) {
var rc = new ReCase(t.typeArguments[1].name);
deserializedRepresentation = '''
map['$alias'] is Map
? new Map.unmodifiable(map['$alias'].keys.fold({}, (out, key) {
? new Map.unmodifiable((map['$alias'] as Map).keys.fold({}, (out, key) {
return out..[key] = ${rc
.pascalCase}Serializer.fromMap(map['$alias'][key]);
.pascalCase}Serializer.fromMap((map['$alias'] as Map)[key]);
}))
: null
''';

View file

@ -1,11 +1,12 @@
name: angel_serialize_generator
version: 2.0.7
version: 2.0.8
description: Model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling.
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/serialize
environment:
sdk: '>=2.0.0-dev.1.2 <2.0.0'
sdk: '>=2.0.0-dev.1.2 <3.0.0'
dependencies:
angel_model: ^1.0.0
angel_serialize: ^2.0.0-alpha
build_config: ">=0.2.4 <2.0.0"
code_buffer: ^1.0.0
@ -15,6 +16,5 @@ dependencies:
recase: ^1.0.0
source_gen: ^0.7.0
dev_dependencies:
angel_framework: ^1.0.0
build_runner: ^0.7.0
test: ">= 0.12.13 < 0.13.0"
build_runner: ^0.9.0
test: ^1.0.0

View file

@ -1,6 +1,6 @@
library angel_serialize.test.models.author;
import 'package:angel_framework/common.dart';
import 'package:angel_model/angel_model.dart';
import 'package:angel_serialize/angel_serialize.dart';
import 'package:collection/collection.dart';
import 'package:meta/meta.dart';

View file

@ -1,6 +1,6 @@
library angel_serialize.test.models.book;
import 'package:angel_framework/common.dart';
import 'package:angel_model/angel_model.dart';
import 'package:angel_serialize/angel_serialize.dart';
import 'package:collection/collection.dart';
part 'book.g.dart';