Decode plain DateTime, also better TypeScript serialization
This commit is contained in:
parent
c02c95344c
commit
1ab858d658
8 changed files with 37 additions and 16 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
# 2.0.5
|
||||||
|
* Deserialization now supports un-serialized `DateTime`.
|
||||||
|
* Better support for regular typed Lists and Maps in TypeScript.
|
||||||
|
|
||||||
# 2.0.4
|
# 2.0.4
|
||||||
* Fields in TypeScript definitions are now nullable by default.
|
* Fields in TypeScript definitions are now nullable by default.
|
||||||
|
|
||||||
|
|
|
@ -139,8 +139,9 @@ class SerializerGenerator extends GeneratorForAnnotation<Serializable> {
|
||||||
|
|
||||||
// Deserialize dates
|
// Deserialize dates
|
||||||
if (dateTimeTypeChecker.isAssignableFromType(field.type))
|
if (dateTimeTypeChecker.isAssignableFromType(field.type))
|
||||||
deserializedRepresentation =
|
deserializedRepresentation = "map['$alias'] != null ? "
|
||||||
"map['$alias'] != null ? DateTime.parse(map['$alias']) : null";
|
"(map['$alias'] is DateTime ? map['$alias'] : DateTime.parse(map['$alias']))"
|
||||||
|
" : null";
|
||||||
|
|
||||||
// Serialize model classes via `XSerializer.toMap`
|
// Serialize model classes via `XSerializer.toMap`
|
||||||
else if (isModelClass(field.type)) {
|
else if (isModelClass(field.type)) {
|
||||||
|
|
|
@ -32,7 +32,8 @@ class TypeScriptDefinitionBuilder implements Builder {
|
||||||
var arg = await compileToTypeScriptType(
|
var arg = await compileToTypeScriptType(
|
||||||
fieldName, type.typeArguments[0], ext, buildStep);
|
fieldName, type.typeArguments[0], ext, buildStep);
|
||||||
typeScriptType = '$arg[]';
|
typeScriptType = '$arg[]';
|
||||||
} else if (isMapToModelType(type)) {
|
} else if (const TypeChecker.fromRuntime(List).isAssignableFromType(type) &&
|
||||||
|
type.typeArguments.length == 2) {
|
||||||
var key = await compileToTypeScriptType(
|
var key = await compileToTypeScriptType(
|
||||||
fieldName, type.typeArguments[0], ext, buildStep);
|
fieldName, type.typeArguments[0], ext, buildStep);
|
||||||
var value = await compileToTypeScriptType(
|
var value = await compileToTypeScriptType(
|
||||||
|
@ -58,7 +59,13 @@ class TypeScriptDefinitionBuilder implements Builder {
|
||||||
..outdent()
|
..outdent()
|
||||||
..writeln('}'));
|
..writeln('}'));
|
||||||
} else if (const TypeChecker.fromRuntime(List).isAssignableFromType(type)) {
|
} else if (const TypeChecker.fromRuntime(List).isAssignableFromType(type)) {
|
||||||
typeScriptType = 'any[]';
|
if (type.typeArguments.length == 0)
|
||||||
|
typeScriptType = 'any[]';
|
||||||
|
else {
|
||||||
|
var arg = await compileToTypeScriptType(
|
||||||
|
fieldName, type.typeArguments[0], ext, buildStep);
|
||||||
|
typeScriptType = '$arg[]';
|
||||||
|
}
|
||||||
} else if (isModelClass(type)) {
|
} else if (isModelClass(type)) {
|
||||||
var ctx = await buildContext(
|
var ctx = await buildContext(
|
||||||
type.element,
|
type.element,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_serialize_generator
|
name: angel_serialize_generator
|
||||||
version: 2.0.4
|
version: 2.0.5
|
||||||
description: Model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling.
|
description: Model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling.
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/serialize
|
homepage: https://github.com/angel-dart/serialize
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
interface Library {
|
interface Library {
|
||||||
id?: string;
|
id?: string;
|
||||||
collection?: BookCollection;
|
collection?: any;
|
||||||
created_at?: any;
|
created_at?: any;
|
||||||
updated_at?: any;
|
updated_at?: any;
|
||||||
}
|
}
|
||||||
interface BookCollection {
|
|
||||||
[key: string]: Book;
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,10 +20,14 @@ abstract class AuthorSerializer {
|
||||||
: null,
|
: null,
|
||||||
obscured: map['obscured'],
|
obscured: map['obscured'],
|
||||||
createdAt: map['created_at'] != null
|
createdAt: map['created_at'] != null
|
||||||
? DateTime.parse(map['created_at'])
|
? (map['created_at'] is DateTime
|
||||||
|
? map['created_at']
|
||||||
|
: DateTime.parse(map['created_at']))
|
||||||
: null,
|
: null,
|
||||||
updatedAt: map['updated_at'] != null
|
updatedAt: map['updated_at'] != null
|
||||||
? DateTime.parse(map['updated_at'])
|
? (map['updated_at'] is DateTime
|
||||||
|
? map['updated_at']
|
||||||
|
: DateTime.parse(map['updated_at']))
|
||||||
: null);
|
: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,10 +75,14 @@ abstract class LibrarySerializer {
|
||||||
})
|
})
|
||||||
: null,
|
: null,
|
||||||
createdAt: map['created_at'] != null
|
createdAt: map['created_at'] != null
|
||||||
? DateTime.parse(map['created_at'])
|
? (map['created_at'] is DateTime
|
||||||
|
? map['created_at']
|
||||||
|
: DateTime.parse(map['created_at']))
|
||||||
: null,
|
: null,
|
||||||
updatedAt: map['updated_at'] != null
|
updatedAt: map['updated_at'] != null
|
||||||
? DateTime.parse(map['updated_at'])
|
? (map['updated_at'] is DateTime
|
||||||
|
? map['updated_at']
|
||||||
|
: DateTime.parse(map['updated_at']))
|
||||||
: null);
|
: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ interface Book {
|
||||||
title?: string;
|
title?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
page_count?: number;
|
page_count?: number;
|
||||||
not_models?: any[];
|
not_models?: number[];
|
||||||
camelCase?: string;
|
camelCase?: string;
|
||||||
created_at?: any;
|
created_at?: any;
|
||||||
updated_at?: any;
|
updated_at?: any;
|
||||||
|
|
|
@ -17,10 +17,14 @@ abstract class BookSerializer {
|
||||||
notModels: map['not_models'],
|
notModels: map['not_models'],
|
||||||
camelCaseString: map['camelCase'],
|
camelCaseString: map['camelCase'],
|
||||||
createdAt: map['created_at'] != null
|
createdAt: map['created_at'] != null
|
||||||
? DateTime.parse(map['created_at'])
|
? (map['created_at'] is DateTime
|
||||||
|
? map['created_at']
|
||||||
|
: DateTime.parse(map['created_at']))
|
||||||
: null,
|
: null,
|
||||||
updatedAt: map['updated_at'] != null
|
updatedAt: map['updated_at'] != null
|
||||||
? DateTime.parse(map['updated_at'])
|
? (map['updated_at'] is DateTime
|
||||||
|
? map['updated_at']
|
||||||
|
: DateTime.parse(map['updated_at']))
|
||||||
: null);
|
: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue