json_annotation
v4.12.0Classes and helper functions that support JSON code generation via the `json_serializable` package.
Архив пакета: https://pubdev.letsnova.ru/api/archives/json_annotation/4.12.0.tar.gz
dart pub add json_annotationREADME
Defines the annotations used by json_serializable to create code for JSON serialization and deserialization.
See the example to understand how to configure your package.
Features and bugs
Please file feature requests and bugs at the issue tracker.
История изменений
4.12.0
- Add
JsonKey.explicitJsonNullWhenNonNullFieldfor PATCH-style tri-state JSON fields (omit key vs explicitnullvs value).
4.11.0
- Add
JsonSerializable.dateTimeUtcconfiguration option. (#1371)
4.10.0
- Support
JsonKeyannotation on constructor parameters. - Add
JsonSerializable(createJsonSchema: true). (Huge thanks to Chris Sells for the PR!) - Require
meta: ^1.16.0 - Require
sdk: ^3.9.0
4.9.0
- Require Dart 3.0
- Add
JsonSerializable(createJsonKeys: true). (#1401)
4.8.1
- Require Dart 2.19
- Add topics.
4.8.0
- DEPRECATED
JsonKey.ignore. Replaced by... - Added
JsonKey.includeFromJsonandJsonKey.includeToJsonto allow fine-grained control of if a field is encoded/decoded. - Added
JsonSerializable.createPerFieldToJsonwhich allows generating a_$ModelPerFieldToJson, enabling partial encoding of a model. - Update
JsonKeydocumentation to align with new features inpackage:json_serializable. - Require Dart SDK
>=2.18.0.
4.7.0
- Added
JsonEnum.valueFieldwhich allows specifying a field in an "enhanced enum" to use for serialization instead of specifying each value individually withJsonValue. - Require Dart SDK 2.17
4.6.0
- Added
JsonSerializable(createFieldMap: true). (#1164) - Added
JsonSerializable(converters: <JsonConverter>[])(#1072)
4.5.0
- Added
FieldRename.screamingSnake.
4.4.0
- Added
JsonKey.readValue. - Non-breaking updates to
checkedCreateandcheckedConvertto supportJsonKey.readValue. - Improved
toStringin included exceptions.
4.3.0
- Changed the type of
JsonKey.unknownEnumValuefromObject?toEnum?. Assuming this feature has been used correctly, it shouldn't be a breaking change. - Changed the type of the
$enumDecodeNullableparameterunknownValuefromObject?toEnum?.
4.2.0
- Added
JsonSerializable.constructorfield to allow specifying an alternative constructor to invoke when creating afromJsonhelper. - Added
JsonEnumfor annotatingenumtypes. - Added
$enumDecodeNullableand$enumDecodehelpers to minimize generated code. - Added
constJsonKey.nullForUndefinedEnumValuefor use inJsonKey.unknownEnumValuewhen you want to usenullfor an unknown value. - Require Dart SDK
>=2.14.0.
4.1.0
- Added a
constconstructor toJsonConverter. - Added
$checkedCreatehelper that will be used bypackage:json_serializablev5+ and replaces both$checkedNewand$checkedConvert. - Annotate annotations with the supported target types, to minimize incorrect usage.
4.0.1
- Fix a potential error with
checked: truewhenArgumentError.messageisnull. - Updated
JsonSerializable.fromJsonto handlenullvalues. - Deprecate
JsonSerializabledefaultsandwithDefaults().
4.0.0
- Support null safety.
- Requires Dart 2.12.
- Updated
$checkedConverthelper to support null-safety. - Removed the
nullablefield onJsonKey– the constructor entry still exists, but it's marked@Deprecated. The nullability of a field is now determined by the Dart type system.
3.1.1
- Avoid
nullvalues forCheckedFromJsonException.messageby usingtoString()with unrecognized error types. - Added a helpful
UnrecognizedKeysException.toString(). - Fixed doc comments for
JsonSerializable.genericArgumentFactories.
3.1.0
- Added
JsonSerializable.genericArgumentFactoriesfield. - Require at least Dart
2.7.0.
3.0.1
- Require at least Dart
2.6.0. - Fix lint that was affecting
pub.devscore.
3.0.0
- BREAKING Removed
JsonSerializable.useWrappersand associated$-prefixed helpers. - BREAKING Removed
JsonSerializable.generateToJsonFunction. - BREAKING Removed
encodeEmptyCollectionfromJsonSerializableandJsonKey. - Added
JsonSerializable.ignoreUnannotated. - Added
JsonKey.unknownEnumValue. - Require at least Dart
2.3.0.
2.4.0
- Deprecate members that will be removed in
json_annotation3.0.0and that are not supported injson_serializable3.0.0.JsonSerializable.useWrappersand associated$-prefixed helpersJsonSerializable.generateToJsonFunction,encodeEmptyCollectionfromJsonSerializableandJsonKey.
2.3.0
- Added
pascalas an additionalfieldRenameoption. - Require at least Dart
2.2.0.
2.2.0
- Add an optional (named)
badKeyparameter and field toCheckedFromJsonException.
2.1.0
-
Require at least Dart
2.1.1. -
Added to
encodeEmptyCollectiontoJsonKeyandJsonSerializable. -
JsonSerializable.fromJsonnow throwsCheckedFromJsonExceptionon errors. This is potentially a breaking change. -
Added a more helpful
toStringtoCheckedFromJsonException.
2.0.0
-
Potentially Breaking
JsonSerializableno longer sets default values for fields when constructor arguments are unset ornull. This is not likely an issue for developers using this class as an annotation with a compatible version ofpackage:json_serializable, but it may cause issues if class is used in other contexts. -
Support all
build.yamlconfiguration options on classes by adding a number of fields toJsonSerializable:anyMap,checked,explicitToJson,generateToJsonFunction, anduseWrappers.
1.2.0
- Added
JsonConverterclass to support custom conversion of types.
1.1.0
- Added the
fieldRenameoption toJsonSerializableand the associatedFieldRenameenum.
1.0.0
-
Added
JsonValueclass for annotatingenumfields with a custom serialization value. -
Removed
$checkAllowedKeys,$enumDecodeand$enumDecodeNullablewhich are no longer needed by the latest release ofpackage:json_serializable.
0.2.9+1
- Support the Dart 2.0 stable release.
0.2.9
- When
FormatExceptionis caught in "checked mode", use themessageproperty when creatingCheckedFromJsonException.
0.2.8
-
Added
$checkKeyshelper function and deprecated$checkAllowedKeys. Upgrading to the latestjson_serializableand re-running your build will eliminate any@deprecatedhints you see. -
Added
BadKeyExceptionexception which is the abstract super class forMissingRequiredKeysException,UnrecognizedKeysException, andDisallowedNullValueException. -
Added
JsonKey.requiredfield and an associatedMissingRequiredKeysExceptionthat is thrown whenrequiredfields don't have corresponding keys in a source JSON map. -
Added
JsonKey.disallowNullValuefield and an associatedDisallowedNullValueExceptionthat is thrown when corresponding keys exist in a source JSON map, but their values arenull. -
Updated documentation of
JsonSerializable.createToJsonto include details of the newgenerate_to_json_functionconfiguration option.
0.2.7+1
- Small improvement to
UnrecognizedKeysException.messageoutput and documentation comments.
0.2.7
- Added
JsonSerializable.disallowUnrecognizedKeys.- Added a helper function to support this option. This function starts with a
$and should only be referenced by generated code. It is not meant for direct use. - Added
UnrecognizedKeysExceptionfor reporting errors.
- Added a helper function to support this option. This function starts with a
0.2.6
-
CheckedFromJsonException- Added a public constructor to support hand-written JSON decoding logic.
- The
messageproperty is nowString(instead ofObject).
-
Added
JsonKey.defaultValue. -
Added helpers for deserialization of
enumvalues. These functions starting with$are referenced by generated code. They are not meant for direct use.
0.2.5
-
Added
CheckedFromJsonExceptionwhich is thrown by code generated whencheckedis enabled injson_serializable. -
Added functions to support the
checkedgeneration option. These functions starting with$are referenced by generated code. They are not meant for direct use.
0.2.4
- Added
fromJsonandtoJsonfields toJsonKeyclass.
0.2.3
- Added
ignorefield toJsonKeyclass annotation
0.2.2
- Added a helper class –
$JsonMapWrapper– and helper functions –$wrapMap,$wrapMapHandleNull,$wrapList, and$wrapListHandleNull– to support theuseWrappersoption added toJsonSerializableGeneratorinv0.3.0ofpackage:json_serializable.
0.2.1
JsonSerializableclass annotation- Added
nullablefield. - Fixed doc comment.
- Added
0.2.0
- Moved annotation classes for
JsonSerializableandJsonLiteral.
