json_annotation library
Provides annotation classes to use with json_serializable.
Also contains helper functions and classes – prefixed with $
used by
json_serializable
when the use_wrappers
or checked
options are
enabled.
Classes
-
JsonConverter<
T, S> - Implement this class to provide custom converters for a specific Type.
- JsonEnum
-
Allows configuration of how
enum
elements are treated as JSON. - JsonKey
- An annotation used to specify how a field is serialized.
- JsonLiteral
- An annotation used to generate a private field containing the contents of a JSON file.
- JsonSerializable
- An annotation used to specify a class to generate code for.
- JsonValue
- An annotation used to specify how a enum value is serialized.
Enums
- FieldRename
- Values for the automatic field renaming behavior for JsonSerializable.
Functions
-
$checkedConvert<
T> (Map map, String key, T castFunc(dynamic), {Object? readValue(Map, String)?}) → T -
Helper function used in generated code when
JsonSerializableGenerator.checked
istrue
. -
$checkedCreate<
T> (String className, Map map, T constructor(S < S>(String, S (Object?), {Object? readValue(Map, String)?}) ), {Map<String, String> fieldKeyMap = const {}}) → T -
Helper function used in generated code when
JsonSerializableGenerator.checked
istrue
. -
$checkedNew<
T> (String className, Map map, T constructor(), {Map< String, String> ? fieldKeyMap}) → T -
Helper function used in generated code when
JsonSerializableGenerator.checked
istrue
. -
$checkKeys(
Map map, {List< String> ? allowedKeys, List<String> ? requiredKeys, List<String> ? disallowNullValues}) → void -
Helper function used in generated
fromJson
code whenJsonSerializable.disallowUnrecognizedKeys
is true for an annotated type orJsonKey.required
istrue
for any annotated fields. -
$enumDecode<
K extends Enum, V> (Map< K, V> enumValues, Object? source, {K? unknownValue}) → K -
Returns the key associated with value
source
fromenumValues
, if one exists. -
$enumDecodeNullable<
K extends Enum, V> (Map< K, V> enumValues, Object? source, {Enum? unknownValue}) → K? -
Returns the key associated with value
source
fromenumValues
, if one exists.
Exceptions / Errors
- BadKeyException
- A base class for exceptions thrown when decoding JSON.
- CheckedFromJsonException
-
Exception thrown if there is a runtime exception in
fromJson
code generated whenJsonSerializableGenerator.checked
istrue
- DisallowedNullValueException
-
Exception thrown if there are keys with disallowed
null
values in a JSON map that was provided during deserialization. - MissingRequiredKeysException
- Exception thrown if there are missing required keys in a JSON map that was provided during deserialization.
- UnrecognizedKeysException
- Exception thrown if there are unrecognized keys in a JSON map that was provided during deserialization.