1
- // Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
1
+ // Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
@@ -19,13 +19,13 @@ class JsonKey {
19
19
final Object ? defaultValue;
20
20
21
21
/// If `true` , generated code will throw a [DisallowedNullValueException] if
22
- /// the corresponding key exists, but the value is `null` .
22
+ /// the corresponding key exists, but its value is `null` .
23
23
///
24
24
/// Note: this value does not affect the behavior of a JSON map *without* the
25
25
/// associated key.
26
26
///
27
27
/// If [disallowNullValue] is `true` , [includeIfNull] will be treated as
28
- /// `false` to ensure compatibility between `toJson` and `fromJson` .
28
+ /// `false` to ensure consistency between `toJson` and `fromJson` .
29
29
///
30
30
/// If both [includeIfNull] and [disallowNullValue] are set to `true` on the
31
31
/// same field, an exception will be thrown during code generation.
@@ -39,40 +39,41 @@ class JsonKey {
39
39
/// type of the annotated field.
40
40
///
41
41
/// When creating a class that supports both `toJson` and `fromJson`
42
- /// (the default), you should also set [toJson] if you set [fromJson] .
43
- /// Values returned by [toJson] should "round-trip" through [fromJson] .
42
+ /// (the default behavior), it is recommended to also set [toJson] if
43
+ /// [fromJson] is set. Values returned by [toJson] should "round-trip"
44
+ /// through [fromJson] .
44
45
final Function ? fromJson;
45
46
46
47
/// `true` if the generator should ignore this field completely.
47
48
///
48
49
/// If `null` (the default) or `false` , the field will be considered for
49
50
/// serialization.
50
51
///
51
- /// This field is DEPRECATED use [includeFromJson] and [includeToJson]
52
+ /// This field is DEPRECATED; use [includeFromJson] and [includeToJson]
52
53
/// instead.
53
54
@Deprecated (
54
55
'Use `includeFromJson` and `includeToJson` with a value of `false` '
55
56
'instead.' ,
56
57
)
57
58
final bool ? ignore;
58
59
59
- /// Used to force a field to be included (or excluded) when decoding a object
60
- /// from JSON.
60
+ /// Determines whether a field should be included (or excluded) when decoding
61
+ /// an object from JSON.
61
62
///
62
- /// `null` (the default) means the field will be handled with the default
63
- /// semantics that take into account if it's private or if it can be cleanly
64
- /// round-tripped to- from JSON.
63
+ /// `null` (the default) means the field will be handled with default
64
+ /// semantics that consider whether it's private or if it can be cleanly
65
+ /// round-tripped to and from JSON.
65
66
///
66
- /// `true` means the field should always be decoded, even if it's private.
67
+ /// `true` forces the field to always be decoded, even if it's private.
67
68
///
68
- /// `false` means the field should never be decoded.
69
+ /// `false` prevents the field from being decoded.
69
70
final bool ? includeFromJson;
70
71
71
- /// Whether the generator should include fields with `null` values in the
72
+ /// Specifies whether fields with `null` values should be included in the
72
73
/// serialized output.
73
74
///
74
- /// If `true` , the generator should include the field in the serialized
75
- /// output, even if the value is `null` .
75
+ /// If `true` , the field will be included in the serialized output even if its
76
+ /// value is `null` .
76
77
///
77
78
/// The default value, `null` , indicates that the behavior should be
78
79
/// acquired from the [JsonSerializable.includeIfNull] annotation on the
@@ -85,44 +86,43 @@ class JsonKey {
85
86
/// same field, an exception will be thrown during code generation.
86
87
final bool ? includeIfNull;
87
88
88
- /// Used to force a field to be included (or excluded) when encoding a object
89
- /// to JSON.
89
+ /// Determines whether a field should be included (or excluded) when encoding
90
+ /// an object to JSON.
90
91
///
91
92
/// `null` (the default) means the field will be handled with the default
92
93
/// semantics that take into account if it's private or if it can be cleanly
93
94
/// round-tripped to-from JSON.
94
95
///
95
- /// `true` means the field should always be encoded, even if it's private.
96
+ /// `true` forces the field to always be encoded, even if it's private.
96
97
///
97
- /// `false` means the field should never be encoded.
98
+ /// `false` prevents the field from being encoded.
98
99
final bool ? includeToJson;
99
100
100
- /// The key in a JSON map to use when reading and writing values corresponding
101
- /// to the annotated fields .
101
+ /// The key to use in the JSON map when reading and writing values for the
102
+ /// annotated field .
102
103
///
103
- /// If `null` , the field name is used.
104
+ /// If `null` , the field name will be used as the key .
104
105
final String ? name;
105
106
106
- /// Specialize how a value is read from the source JSON map.
107
+ /// Customizes how a value is read from the source JSON map.
107
108
///
108
109
/// Typically, the value corresponding to a given key is read directly from
109
110
/// the JSON map using `map[key]` . At times it's convenient to customize this
110
111
/// behavior to support alternative names or to support logic that requires
111
112
/// accessing multiple values at once.
112
113
///
113
- /// The provided, the [Function] must be a top-level or static within the
114
- /// using class.
114
+ /// The provided [Function] must be either a top-level function or a static
115
+ /// method within the class.
115
116
///
116
117
/// Note: using this feature does not change any of the subsequent decoding
117
118
/// logic for the field. For instance, if the field is of type [DateTime] we
118
119
/// expect the function provided here to return a [String] .
119
120
final Object ? Function (Map , String )? readValue;
120
121
121
- /// When `true` , generated code for `fromJson` will verify that the source
122
- /// JSON map contains the associated key.
122
+ /// If `true` , generated code for `fromJson` will verify that the source JSON
123
+ /// map contains the associated key.
123
124
///
124
- /// If the key does not exist, a [MissingRequiredKeysException] exception is
125
- /// thrown.
125
+ /// If the key is missing, a [MissingRequiredKeysException] will be thrown.
126
126
///
127
127
/// Note: only the existence of the key is checked. A key with a `null` value
128
128
/// is considered valid.
@@ -135,23 +135,23 @@ class JsonKey {
135
135
/// returns a JSON-compatible value.
136
136
///
137
137
/// When creating a class that supports both `toJson` and `fromJson`
138
- /// (the default), you should also set [fromJson] if you set [toJson] .
139
- /// Values returned by [toJson] should "round-trip" through [fromJson] .
138
+ /// (the default behavior), it is recommended to also set [fromJson] if
139
+ /// [toJson] is set. Values returned by [toJson] should "round-trip" through
140
+ /// [fromJson] .
140
141
final Function ? toJson;
141
142
142
- /// The value to use for an enum field when the value provided is not in the
143
- /// source enum.
143
+ /// The value to use for an enum field when the provided value does not match
144
+ /// any of the values in the source enum.
144
145
///
145
146
/// Valid only on enum fields with a compatible enum value.
146
147
///
147
- /// If you want to use the value `null` when encountering an unknown value,
148
- /// use the value of [JsonKey.nullForUndefinedEnumValue] instead. This is only
149
- /// valid on a nullable enum field.
148
+ /// To use `null` for unknown values, use [JsonKey.nullForUndefinedEnumValue] .
149
+ /// This is only valid for nullable enum fields.
150
150
final Enum ? unknownEnumValue;
151
151
152
152
/// Creates a new [JsonKey] instance.
153
153
///
154
- /// Only required when the default behavior is not desired.
154
+ /// Use this constructor when the default behavior is not desired.
155
155
const JsonKey ({
156
156
@Deprecated ('Has no effect' ) bool ? nullable,
157
157
this .defaultValue,
0 commit comments