/
default_value_interface.dart
70 lines (43 loc) · 1.53 KB
/
default_value_interface.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2018, the Dart project authors. 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:json_annotation/json_annotation.dart';
abstract class DefaultValue {
bool get fieldBool;
String get fieldString;
int get fieldInt;
double get fieldDouble;
List get fieldListEmpty;
Map get fieldMapEmpty;
Set get fieldSetEmpty;
List<int> get fieldListSimple;
Set<String> get fieldSetSimple;
Map<String, int> get fieldMapSimple;
Map<String, List<String>> get fieldMapListString;
Duration get durationField;
Greek get fieldEnum;
ConstClass get constClass;
ConstClass get valueFromConverter;
ConstClass get valueFromFunction;
}
enum Greek { alpha, beta, gamma, delta }
// Regression for https://github.com/google/json_serializable.dart/issues/903
class ConstClass {
final String field;
const ConstClass(this.field);
factory ConstClass.fromJson(Map<String, dynamic> json) => ConstClass(
json['field'] as String,
);
Map<String, dynamic> toJson() => <String, dynamic>{
'field': field,
};
}
ConstClass constClassFromJson(String json) => ConstClass(json);
String constClassToJson(ConstClass object) => object.field;
class ConstClassConverter extends JsonConverter<ConstClass, String> {
const ConstClassConverter();
@override
ConstClass fromJson(String json) => ConstClass(json);
@override
String toJson(ConstClass object) => object.field;
}