platform/angel_serialize_generator/test/models/author.serializer.g.dart

179 lines
5.1 KiB
Dart
Raw Normal View History

// GENERATED CODE - DO NOT MODIFY BY HAND
part of angel_serialize.test.models.author;
// **************************************************************************
// Generator: SerializerGenerator
// **************************************************************************
2018-02-28 01:10:57 +00:00
abstract class AuthorSerializer {
2018-03-09 12:45:03 +00:00
static Author fromMap(Map map) {
2018-05-15 19:33:57 +00:00
if (map['name'] == null) {
throw new FormatException("Missing required field 'name' on Author.");
}
if (map['age'] == null) {
throw new FormatException("Custom message for missing `age`");
}
2018-02-28 02:10:43 +00:00
return new Author(
id: map['id'],
name: map['name'],
age: map['age'],
books: map['books'] is Iterable
2018-05-15 19:01:13 +00:00
? new List.unmodifiable(map['books'].map(BookSerializer.fromMap))
2018-02-28 02:10:43 +00:00
: null,
newestBook: map['newest_book'] != null
? BookSerializer.fromMap(map['newest_book'])
: null,
obscured: map['obscured'],
2018-02-28 02:10:43 +00:00
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
? map['created_at']
: DateTime.parse(map['created_at']))
2018-02-28 02:10:43 +00:00
: null,
updatedAt: map['updated_at'] != null
? (map['updated_at'] is DateTime
? map['updated_at']
: DateTime.parse(map['updated_at']))
2018-02-28 02:10:43 +00:00
: null);
}
2018-02-28 01:41:19 +00:00
static Map<String, dynamic> toMap(Author model) {
2018-05-15 19:33:57 +00:00
if (model.name == null) {
throw new FormatException("Missing required field 'name' on Author.");
}
if (model.age == null) {
throw new FormatException("Custom message for missing `age`");
}
2018-02-28 01:10:57 +00:00
return {
2018-02-28 01:41:19 +00:00
'id': model.id,
'name': model.name,
'age': model.age,
2018-02-28 02:10:43 +00:00
'books': model.books?.map(BookSerializer.toMap)?.toList(),
2018-02-28 01:41:19 +00:00
'newest_book': BookSerializer.toMap(model.newestBook),
2018-02-28 02:10:43 +00:00
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
2018-02-28 01:10:57 +00:00
};
}
}
2018-03-09 12:39:21 +00:00
abstract class AuthorFields {
static const String id = 'id';
static const String name = 'name';
static const String age = 'age';
static const String books = 'books';
static const String newestBook = 'newest_book';
static const String secret = 'secret';
static const String obscured = 'obscured';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
}
2018-02-28 01:10:57 +00:00
abstract class LibrarySerializer {
2018-03-09 12:45:03 +00:00
static Library fromMap(Map map) {
2018-02-28 02:10:43 +00:00
return new Library(
id: map['id'],
collection: map['collection'] is Map
2018-05-15 19:01:13 +00:00
? new Map.unmodifiable(map['collection'].keys.fold({}, (out, key) {
2018-02-28 02:10:43 +00:00
return out
..[key] = BookSerializer.fromMap(map['collection'][key]);
2018-05-15 19:01:13 +00:00
}))
2018-02-28 02:10:43 +00:00
: null,
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
? map['created_at']
: DateTime.parse(map['created_at']))
2018-02-28 02:10:43 +00:00
: null,
updatedAt: map['updated_at'] != null
? (map['updated_at'] is DateTime
? map['updated_at']
: DateTime.parse(map['updated_at']))
2018-02-28 02:10:43 +00:00
: null);
}
2018-02-28 01:41:19 +00:00
static Map<String, dynamic> toMap(Library model) {
2018-02-28 01:10:57 +00:00
return {
2018-02-28 01:41:19 +00:00
'id': model.id,
2018-02-28 02:10:43 +00:00
'collection': model.collection.keys?.fold({}, (map, key) {
2018-02-28 01:43:43 +00:00
return map..[key] = BookSerializer.toMap(model.collection[key]);
}),
2018-02-28 02:10:43 +00:00
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
2018-02-28 01:10:57 +00:00
};
}
}
2018-03-09 12:39:21 +00:00
abstract class LibraryFields {
static const String id = 'id';
static const String collection = 'collection';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
}
2018-05-13 17:23:40 +00:00
abstract class BookmarkSerializer {
static Bookmark fromMap(Map map, Book book) {
2018-05-15 19:33:57 +00:00
if (map['page'] == null) {
throw new FormatException("Missing required field 'page' on Bookmark.");
}
2018-05-13 17:23:40 +00:00
return new Bookmark(book,
id: map['id'],
2018-05-13 18:02:47 +00:00
history: map['history'],
2018-05-13 17:23:40 +00:00
page: map['page'],
comment: map['comment'],
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
? map['created_at']
: DateTime.parse(map['created_at']))
: null,
updatedAt: map['updated_at'] != null
? (map['updated_at'] is DateTime
? map['updated_at']
: DateTime.parse(map['updated_at']))
: null);
}
static Map<String, dynamic> toMap(Bookmark model) {
2018-05-15 19:33:57 +00:00
if (model.page == null) {
throw new FormatException("Missing required field 'page' on Bookmark.");
}
2018-05-13 17:23:40 +00:00
return {
'id': model.id,
2018-05-13 18:02:47 +00:00
'history': model.history,
2018-05-13 17:23:40 +00:00
'page': model.page,
'comment': model.comment,
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
};
}
}
abstract class BookmarkFields {
static const String id = 'id';
2018-05-13 18:02:47 +00:00
static const String history = 'history';
2018-05-13 17:23:40 +00:00
static const String page = 'page';
static const String comment = 'comment';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
}