-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
json_key.dart
26 lines (21 loc) · 929 Bytes
/
json_key.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
// Copyright (c) 2024, 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:meta/meta_meta.dart';
/// An annotation used to specify how a field is serialized.
@Target({TargetKind.field})
class JsonKey {
/// The key in a JSON map to use when reading and writing values corresponding
/// to the annotated fields.
///
/// If `null`, the field name is used.
final String? name;
/// The value to use if the source JSON does not contain this key.
///
/// If the value is explicitly null in the JSON, it will still be retained.
final Object? defaultValue;
/// Whether or not to include this field in the serialized form, even if it
/// is `null`.
final bool includeIfNull;
const JsonKey({this.name, this.defaultValue, this.includeIfNull = false});
}