-
Notifications
You must be signed in to change notification settings - Fork 409
/
Copy pathjson_enum.dart
52 lines (45 loc) · 1.81 KB
/
json_enum.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
// Copyright (c) 2021, 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';
import 'json_serializable.dart';
import 'json_value.dart';
/// Allows configuration of how `enum` elements are treated as JSON.
@Target({TargetKind.enumType})
class JsonEnum {
const JsonEnum({
this.alwaysCreate = false,
this.fieldRename = FieldRename.none,
this.caseInsensitive = false,
this.valueField,
});
/// If `true`, `_$[enum name]EnumMap` is generated for in library containing
/// the `enum`, even if the `enum` is not used as a field in a class annotated
/// with [JsonSerializable].
///
/// The default, `false`, means no extra helpers are generated for this `enum`
/// unless it is used by a class annotated with [JsonSerializable].
final bool alwaysCreate;
/// Defines the naming strategy when converting enum entry names to JSON
/// values.
///
/// With a value [FieldRename.none] (the default), the name of the enum entry
/// is used without modification.
///
/// See [FieldRename] for details on the other options.
///
/// Note: the value for [JsonValue.value] takes precedence over this option
/// for entries annotated with [JsonValue].
final FieldRename fieldRename;
/// If `true`, enum comparison will be done using case-insensitive.
///
/// The default, `false`, means enum comparison will be done using
/// case-sensitive.
final bool caseInsensitive;
/// Specifies the field within an "enhanced enum" to use as the value
/// to use for serialization.
///
/// If an individual `enum` element is annotated with `@JsonValue`
/// that value still takes precedence.
final String? valueField;
}