platform/packages/serialize/serialize_generator/test/models/subclass.g.dart

233 lines
4.9 KiB
Dart
Raw Normal View History

2019-07-04 18:30:45 +00:00
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'subclass.dart';
// **************************************************************************
// JsonModelGenerator
// **************************************************************************
@generatedSerializable
class Animal extends _Animal {
2023-04-21 06:25:54 +00:00
Animal({
required this.genus,
required this.species,
});
2019-07-04 18:30:45 +00:00
@override
2021-05-02 06:02:08 +00:00
String? genus;
2019-07-04 18:30:45 +00:00
@override
2021-05-02 06:02:08 +00:00
String? species;
2019-07-04 18:30:45 +00:00
2023-04-21 06:25:54 +00:00
Animal copyWith({
String? genus,
String? species,
}) {
2019-07-04 18:30:45 +00:00
return Animal(genus: genus ?? this.genus, species: species ?? this.species);
}
2021-06-26 13:13:43 +00:00
@override
2019-07-04 18:30:45 +00:00
bool operator ==(other) {
return other is _Animal && other.genus == genus && other.species == species;
}
@override
int get hashCode {
2023-04-21 06:25:54 +00:00
return hashObjects([
genus,
species,
]);
2019-07-04 18:30:45 +00:00
}
@override
String toString() {
2021-06-26 13:13:43 +00:00
return 'Animal(genus=$genus, species=$species)';
2019-07-04 18:30:45 +00:00
}
Map<String, dynamic> toJson() {
return AnimalSerializer.toMap(this);
}
}
@generatedSerializable
class Bird extends _Bird {
2023-04-21 06:25:54 +00:00
Bird({
required this.genus,
required this.species,
this.isSparrow = false,
});
2019-07-04 18:30:45 +00:00
@override
2021-05-02 06:02:08 +00:00
String? genus;
2019-07-04 18:30:45 +00:00
@override
2021-05-02 06:02:08 +00:00
String? species;
2019-07-04 18:30:45 +00:00
@override
2021-05-02 06:02:08 +00:00
bool? isSparrow;
2019-07-04 18:30:45 +00:00
2023-04-21 06:25:54 +00:00
Bird copyWith({
String? genus,
String? species,
bool? isSparrow,
}) {
2019-07-04 18:30:45 +00:00
return Bird(
genus: genus ?? this.genus,
species: species ?? this.species,
isSparrow: isSparrow ?? this.isSparrow);
}
2021-06-26 13:13:43 +00:00
@override
2019-07-04 18:30:45 +00:00
bool operator ==(other) {
return other is _Bird &&
other.genus == genus &&
other.species == species &&
other.isSparrow == isSparrow;
}
@override
int get hashCode {
2023-04-21 06:25:54 +00:00
return hashObjects([
genus,
species,
isSparrow,
]);
2019-07-04 18:30:45 +00:00
}
@override
String toString() {
2021-06-26 13:13:43 +00:00
return 'Bird(genus=$genus, species=$species, isSparrow=$isSparrow)';
2019-07-04 18:30:45 +00:00
}
Map<String, dynamic> toJson() {
return BirdSerializer.toMap(this);
}
}
// **************************************************************************
// SerializerGenerator
// **************************************************************************
const AnimalSerializer animalSerializer = AnimalSerializer();
class AnimalEncoder extends Converter<Animal, Map> {
const AnimalEncoder();
@override
Map convert(Animal model) => AnimalSerializer.toMap(model);
}
class AnimalDecoder extends Converter<Map, Animal> {
const AnimalDecoder();
@override
Animal convert(Map map) => AnimalSerializer.fromMap(map);
}
class AnimalSerializer extends Codec<Animal, Map> {
const AnimalSerializer();
@override
2021-06-26 13:13:43 +00:00
AnimalEncoder get encoder => const AnimalEncoder();
2019-07-04 18:30:45 +00:00
@override
2021-06-26 13:13:43 +00:00
AnimalDecoder get decoder => const AnimalDecoder();
2019-07-04 18:30:45 +00:00
static Animal fromMap(Map map) {
if (map['genus'] == null) {
throw FormatException("Missing required field 'genus' on Animal.");
}
if (map['species'] == null) {
throw FormatException("Missing required field 'species' on Animal.");
}
return Animal(
2021-05-02 06:02:08 +00:00
genus: map['genus'] as String?, species: map['species'] as String?);
2019-07-04 18:30:45 +00:00
}
2022-02-27 04:16:31 +00:00
static Map<String, dynamic> toMap(_Animal? model) {
if (model == null) {
throw FormatException("Required field [model] cannot be null");
2019-07-04 18:30:45 +00:00
}
return {'genus': model.genus, 'species': model.species};
}
}
abstract class AnimalFields {
2023-04-21 06:25:54 +00:00
static const List<String> allFields = <String>[
genus,
species,
];
2019-07-04 18:30:45 +00:00
static const String genus = 'genus';
static const String species = 'species';
}
const BirdSerializer birdSerializer = BirdSerializer();
class BirdEncoder extends Converter<Bird, Map> {
const BirdEncoder();
@override
Map convert(Bird model) => BirdSerializer.toMap(model);
}
class BirdDecoder extends Converter<Map, Bird> {
const BirdDecoder();
@override
Bird convert(Map map) => BirdSerializer.fromMap(map);
}
class BirdSerializer extends Codec<Bird, Map> {
const BirdSerializer();
@override
2021-06-26 13:13:43 +00:00
BirdEncoder get encoder => const BirdEncoder();
2019-07-04 18:30:45 +00:00
@override
2021-06-26 13:13:43 +00:00
BirdDecoder get decoder => const BirdDecoder();
2019-07-04 18:30:45 +00:00
static Bird fromMap(Map map) {
if (map['genus'] == null) {
throw FormatException("Missing required field 'genus' on Bird.");
}
if (map['species'] == null) {
throw FormatException("Missing required field 'species' on Bird.");
}
return Bird(
2021-05-02 06:02:08 +00:00
genus: map['genus'] as String?,
species: map['species'] as String?,
isSparrow: map['is_sparrow'] as bool? ?? false);
2019-07-04 18:30:45 +00:00
}
2022-02-27 04:16:31 +00:00
static Map<String, dynamic> toMap(_Bird? model) {
if (model == null) {
throw FormatException("Required field [model] cannot be null");
2019-07-04 18:30:45 +00:00
}
return {
'genus': model.genus,
'species': model.species,
'is_sparrow': model.isSparrow
};
}
}
abstract class BirdFields {
2023-04-21 06:25:54 +00:00
static const List<String> allFields = <String>[
genus,
species,
isSparrow,
];
2019-07-04 18:30:45 +00:00
static const String genus = 'genus';
static const String species = 'species';
static const String isSparrow = 'is_sparrow';
}