json_serializable 6.11.1
json_serializable: ^6.11.1 copied to clipboard
Automatically generate code for converting to and from JSON by annotating Dart classes.
6.11.1 #
- Allow
build: '>=3.0.0 <5.0.0'. - Allow
source_gen: '>=3.1.0 <5.0.0'.
6.11.0 #
- Support
JsonKeyannotation on constructor parameters. - Require
analyzer: '>=7.4.0 <9.0.0' - Require
dart_style: ^3.0.0 - Require
meta: ^1.15.0 - Require
source_helper: ^1.3.6 - Require
source_gen: ^3.1.0, stop using deprecatedTypeChecker.fromRuntimeand use the newTypeChecker.typeNamedinstead.
6.10.0 #
- Required
analyzer: ^7.4.0. - Switch to analyzer element2 model and
build: ^3.0.0-dev. - Move
package:collectionto a dev dependency. - Use new
null-aware elementfeature in generated code. - Require Dart 3.8
6.9.5 #
- Support the
analyzer: '>=6.9.0 <8.0.0'. - Fixed use of deprecated analyzer APIs.
6.9.4 #
- Fix extra line being generated when targeting Dart 3.7 package.
6.9.3 #
- Error out if the target package does not have a language version of
3.0or greater.
6.9.2 #
- Support the latest
package:analyzer.
6.9.1 #
- Support the latest
package:source_gen. - Require Dart 3.6
6.9.0 #
- Use conditional map syntax to clean up
nullhandling intoJsonfunctions. - Fix core Dart type links in docs.
- Require Dart 3.5
6.8.0 #
- Add type arguments to
Mapliterals used forRecordserialization. - Add support for
JsonSerializable(createJsonKeys: true). (#1401) - Handle decoding an
intvalue from adoubleliteral. This now matches the behavior ofdoublevalues being encoded asint.
6.7.1 #
- Support the latest
package:analyzer.
6.7.0 #
- Support
Recordtypes. - Require Dart 3.0
- Require
analyzer: ^5.12.0
6.6.2 #
- Better handling of
Object?ordynamicasfromJsonconstructor param. - Require Dart 2.19
6.6.1 #
- Fix bug when
JsonKey.includeToJsonisfalse.
6.6.0 #
- Support for
JsonKey.includeFromJsonandJsonKey.includeToJson. - Support
JsonEnum.valueFieldbeing set with'index'. - Support
JsonSerializable.createPerFieldToJson. - Require Dart SDK
>=2.18.0. - Require
analyzer: ^5.2.0 - Require
json_annotation: '>=4.8.0 <4.9.0'
6.5.4 #
- Fixed handling of nullable fields with converters which return non-nullable values.
6.5.3 #
- Fixed handling of nullable
enumfields withincludeIfNull: false.
6.5.2 #
- Better handling of
nullwhen encodingenumvalues or values with conversions.
6.5.1 #
- Fixed
BigInt,DateTime, andUrisupport forJsonKey.defaultValuewith a function value.
6.5.0 #
- Allow constructors to be passed to
JsonKeyparameters that supportFunctiontypes. - Accept
Functionvalues forJsonKey.defaultValue. The providedFunctionwill be invoked for the default value if the target JSON element is missing ornull.
6.4.1 #
- Fixed a bug when an
@JsonSerializableclass uses a mixin with fields. - Added more documentation
@JsonEnum.
6.4.0 #
- Add support for
JsonEnum.valueFieldwhich allows specifying a field in an "enhanced enum" to use for serialization instead of specifying each value individually with `JsonValue - Require
json_annotation: '>=4.7.0 <4.8.0'
6.3.2 #
- Require
analyzer: '>=4.6.0 <6.0.0' - Require
sdk: '>=2.17.0 <3.0.0'
6.3.0 #
- Added support for generating
_$ExampleFieldMap, which can be used by other code-generators that needs to interact with JSON serialization. (#1164) - Added support for using a
JsonConverter<MyClass, Object>on properties of typeMyClass?. (#822) - Added support for
JsonSerializable(converters: <JsonConverter>[])(#1072) - Fix issue with serialization of non-nullable enumerations emitting a nullable type (#1146)
6.2.0 #
- Added support for the new
FieldRename.screamingSnakefield inpackage:json_annotation.
6.1.6 #
- Allow latest
package:analyzer.
6.1.5 #
- Fix enum support for upcoming enhanced enums in Dart 2.17.
6.1.4 #
- Fix issues with latest
package:analyzerrelated to enums and annotations.
6.1.3 #
- Allow latest
package:analyzer.
6.1.1 #
- Fix
JsonKey.readValuesupport to allow static functions.
6.1.0 #
- Support
JsonKey.readValueto allow customized reading of values from source JSON map objects. - The check to make sure there is a correctly constrained dependency on
package:json_annotationis now a warning and doesn't fail the build. - Require
json_annotation'>=4.4.0 <4.5.0'.
6.0.1 #
- Don't require
json_annotationindependenciesif it's just used in tests.
6.0.0 #
- Added support for
JsonSerializable.constructorto allow specifying an alternative constructor to invoke when creating afromJsonhelper. - Support the new
@JsonEnumannotation inpackage:json_annotation. - Support
JsonKey.nullForUndefinedEnumValueas a value forJsonKey.unknownEnumValuewhen you want to usenullas the unknown value. - Use the new
$enumDecodeNullableand$enumDecodein `json_annotation' instead of generating these for each library. NOTE: This is a potential breaking change if any user code relies on the previously generated private functions. - The builder now checks to make sure there is a correctly constrained
dependency on
package:json_annotation. - Require Dart SDK
>=2.14.0. - Require
json_annotation'>=4.3.0 <4.4.0'.
5.0.2 #
- Include type arguments when invoking
fromJsonon custom types. This fixes an edge case where the generic arguments could not be inferred.
5.0.1 #
- Correctly handle nullable custom objects within
IterableandMap. - Require the latest
package:source_helper.
5.0.0 #
- Use the default value for optional constructor parameters if
JsonKey.defaultValueis not provided. This could be a breaking behavior change in generated code in some cases. - Fixed
fromJsonforMapfields with nullable values. - Improve names of private classes generated for
toJsonandfromJson. - Use the new
$checkedCreatehelper exposed inpackage:json_annotationv4.1+. - Generated code now conforms to this
prefer_expression_function_bodieslint. - Support default values and types with a
fromJsonconstructor. - Support default values with class- and function-based converters.
type_helper.dart:- BREAKING: removed
typeArgumentsOf. This is now an extension exposed bypackage:source_helper.
- BREAKING: removed
- Require
package:analyzer^2.0.0.
4.1.4 #
- Allow the latest
package:json_annotation.
4.1.3 #
- Correctly handle nullable types with type arguments in generated code.
4.1.2 #
- Correctly decode
Map<String, double>when the input hasintliterals.
4.1.1 #
- Allow the latest
package:build_config.
4.1.0 #
-
Implementation is now null-safe.
-
Correctly handle nullable generic fields (
T?) withgenericArgumentFactories. -
type_helper.dart- BREAKING changes- The API is now null-safe.
- new
KeyConfigclass replacesJsonKey. - new
ClassConfigclass replacesJsonSerializable.
4.0.3 #
- Correctly handle nullable values with
genericArgumentFactories. - Require the latest
package:build.
4.0.2 #
- Correctly handle nullable
MapandIterableJSON types exposed by both class- and function-based converters.
4.0.1 #
- Allow latest
package:analyzer.
4.0.0 #
- Requires Dart 2.12 or greater.
- Generates null-safe code.
- The
nullablefield onJsonKeyignored. The nullability of a field is now determined by the Dart type system.
- The
- BREAKING
bool defaultProvidedarg added toTypeHelper.deserialize. Only applies to code usingTypeHelperdirectly.
3.5.2 #
- Widen
package:analyzerrange to allow v1.x.
3.5.1 #
- Improved error messages for unsupported types.
package:json_serializable/type_helper.dart- Made the third parameter to
UnsupportedTypeErrorpositional (optional).
- Made the third parameter to
- Require
package:analyzer>=0.39.0 <0.42.0.
3.5.0 #
-
Added support for populating generic helper functions for fields with generic type parameters.
-
Added support for
JsonSerializable.genericArgumentFactories. This adds extra parameters to generatedfromJsonand/ortoJsonfunctions to support encoding and decoding generic types.For example, the generated code for
@JsonSerializable(genericArgumentFactories: true) class Response<T> { int status; T value; }Looks like
Response<T> _$ResponseFromJson<T>( Map<String, dynamic> json, T Function(Object json) fromJsonT, ) { return Response<T>() ..status = json['status'] as int ..value = fromJsonT(json['value']); } Map<String, dynamic> _$ResponseToJson<T>( Response<T> instance, Object Function(T value) toJsonT, ) => <String, dynamic>{ 'status': instance.status, 'value': toJsonT(instance.value), }; -
JsonKey.unknownEnumValue: Added support forIterable,List, andSet. -
Require
package:analyzer>=0.39.0 <0.41.0.
3.4.1 #
- Support properties where the getter is defined in a class with a corresponding setter in a super type.
3.4.0 #
JsonKey.defaultValue- Added support for
double.infinity,double.negativeInfinity, anddouble.nan. - Added support for
Setliterals.
- Added support for
- Require at least Dart
2.7.0.
3.3.0 #
- Add support for fields annotated subclasses of
JsonKey. - Export the following
TypeHelperimplementations and interfaces inpackage:json_serializable/type_helper.dart:DurationHelperTypeHelperContextWithConfig
3.2.5 #
- Fix lint affecting
pub.devscore.
3.2.4 #
- Require
package:analyzer^0.39.0.
3.2.3 #
- Fixed bug related to
package:analyzer0.38.5.
3.2.2 #
- Support
JsonConverterannotations on property getters
3.2.1 #
- Support
package:analyzer>=0.33.3 <0.39.0
3.2.0 #
- Require
package:json_annotation^3.0.0. - Added support for
JsonSerializable.ignoreUnannotated. - Added support for
JsonKey.unknownEnumValue. - Small change to how
enumsupport code is generated. - Require at least Dart
2.3.0.
3.1.0 #
- Support
Mapkeys of typeint,BigInt,DateTime, andUri. - Trailing commas are now added to generated constructor arguments and the
elements in
Mapliterals. - Support
package:analyzer>=0.33.3 <0.38.0
3.0.0 #
This release is entirely BREAKING changes. It removes underused features that added disproportionate complexity to this package. This cleanup should ease future feature work.
- Removed support for
JsonSerializable.useWrappers. - Removed support for
JsonSerializable.generateToJsonFunction. - Removed support for
encodeEmptyCollection. - If a field has a conversion function defined – either
JsonKey.toJsonor a customJsonConverterannotation – don't interceptnullvalues, even ifnullableis explicitly set tofalse. This allows these functions to provide alternative values fornull– such as an empty collection – which replaces the functionality provided byencodeEmptyCollection.- NOTE: this is SILENTLY BREAKING. There is no corresponding deprecation for this change. If you use converters, please make sure to test your code!
2.3.0 #
- Added
pascalas an additionalfieldRenameoption.
2.2.3 #
- Removed special handling of undefined types due to changes in
package:analyzer. These types are now treated asdynamic.
2.2.2 #
- Require at least Dart
2.2.0. - Allow
build_config0.4.x.
2.2.1 #
- Fixed an error when a property/field is defined in a
mixin.
2.2.0 #
- If a field has a conversion function defined – either
JsonKey.toJsonor a customJsonConverterannotation – handle the case where the function returnsnulland bothnullableandincludeIfNullarefalse.
2.1.2 #
- Support
package:json_annotation>=2.1.0 <2.3.0.
2.1.1 #
- Support
package:analyzer>=0.33.3 <0.37.0
2.1.0 #
-
Require at least Dart
2.1.1. -
Added support for
encodeEmptyCollectiononJsonKeyandJsonSerializable. -
Added support for
BigInt. -
Added
BigIntTypeHelpertotype_helper.dartlibrary. -
Provide a more helpful error if the builder is improperly configured.
2.0.3 #
-
When invoking a
fromJsonconstructor on a field type, generate a conversion expression derived from the constructor parameter type. -
Be more strict about the supported
List,Set, orMaptypes. This may cause errors to be raised in cases where invalid code was generated before. It also allows implementations of these types to add afromJsonconstructor to support custom decoding. -
Small change to the whitespace around converted maps to improve a very slow path when formatting generated code.
2.0.2 #
-
Log warnings when
JsonKey.defaultValueis set with other fields.- With
toJson: usenullable: falseinstead ofdefaultValue. - With both
disallowNullValueandrequiredset totrue.
- With
-
Avoid no-op call to
mapwhen decoding a field of typeSet. -
Support
package:analyzer>=0.33.3 <0.36.0
2.0.1 #
- Support
package:analyzerv0.34.0.
2.0.0 #
-
Support all
build.yamlconfiguration options on classes by adding a number of fields toJsonSerializable:anyMap,checked,explicitToJson,generateToJsonFunction, anduseWrappers. -
Support decode/encode of
dart:coreDuration -
Code generated for fields and classes annotated with
JsonConverterinstances now properly handles nullable fields. -
Build configuration
-
You can now configure all settings exposed by the
JsonSerializableannotation withinbuild.yaml. -
BREAKING Unsupported options defined in
build.yamlwill cause exceptions instead of being logged and ignored.
-
-
json_serializable.dart- BREAKING
JsonSerializableGeneratornow exposes aconfigproperty of typeJsonSerializableinstead of individual properties forchecked,anyMay, etc. This will affect creating or using this class via code.
- BREAKING
-
type_helper.dart-
BREAKING
SerializeContextandDeserializeContexthave been replaced with newTypeHelperContextclass. -
TypeHelpernow has a type argument allowing implementors to specify a specific implementation ofTypeHelperContextfor calls toserializeanddeserialize. Many of the includedTypeHelperimplementations have been updated to indicate they expect more information from the source generator.
-
1.5.1 #
- Support the latest
package:analyzer.
1.5.0 #
- Added support for
JsonConvertannotation on fields.
1.4.0 #
-
type_helper.dartTypeHelperserializeanddeserializehave return typeObjectinstead ofString. This allows coordination between instances to support more advanced features – like using the newLambdaResultclass to avoid creating unnecessary lambdas. When creatingTypeHelperimplementations, handle non-Stringresults by callingtoString()on unrecognized values.
-
Declare support for
package:buildversion1.x.x.
1.3.0 #
-
Add support for types annotated with classes that extend
JsonConverterfrompackage:json_annotation. -
Export the following
TypeHelperimplementations inpackage:json_serializable/type_helper.dart:ConvertHelper,EnumHelper,IterableHelper,JsonConverterHelper,MapHelper,ValueHelper -
Added support for
Settype as a target.
1.2.1 #
- Added back
constfor maps generated withchecked: trueconfiguration.
1.2.0 #
-
Now throws
InvalidGenerationSourceErrorinstead ofUnsupportedErrorfor some classes of constructor errors. -
Supports class-static functions for
toJsonandfromJsononJsonKey. -
Provide a warning about ignored setter-only properties instead of crashing.
-
Added back
constfor lists generated withdisallowUnrecognizedKeys,required, anddisallowNullValue. -
Fixed a bug when
disallowUnrecognizedKeysis enabled. -
Fixed a number of issues when dealing with inherited properties.
1.1.0 #
- Added support for automatically converting field names to JSON map keys as
kebab-caseorsnake_casewith a new option on theJsonSerializableannotation.
1.0.1 #
- Explicit
newandconstare no longer generated.
1.0.0 #
-
BREAKING By default, code generated to support
toJsonnow creates a top-level function instead of a mixin. The default for thegenerate_to_json_functionis nowtrue. To opt-out of this change, setgenerate_to_json_functiontofalse. -
Now supports changing the serialized values of enums using
JsonValue.enum AutoApply { none, dependents, @JsonValue('all_packages') allPackages, @JsonValue('root_package') rootPackage } -
JsonSerializableGenerator.generateForAnnotatedElementnow returnsIterable<String>instead ofString. -
SerializeContextandDeserializeContextnow have anaddMemberfunction which allowsTypeHelperinstances to add additional members when handling a field. This is useful for generating shared helpers, for instance. -
BREAKING The
headeroption is no longer supported and must be removed frombuild.yaml. -
If a manual build script is used the
json_serializablebuilder must be switched tohideOutput: true, and thecombiningBuilderfromsource_genmust be included following this builder. When using a generated build script withpub run build_runnerorwebdevthis is handled automatically.
0.5.8+1 #
- Support the Dart 2.0 stable release.
0.5.8 #
-
Small fixes to support Dart 2 runtime semantics.
-
Support serializing types provided by platform-specific libraries (such as Flutter) if they use custom convert functions.
0.5.7 #
-
Added support for
JsonKey.required.- When
true, generated code throws aMissingRequiredKeysExceptionif the key does not exist in the JSON map used to populate the annotated field. - Will be captured and wrapped in a
CheckedFromJsonExceptionifcheckedis enabled injson_serializable.
- When
-
Added
JsonKey.disallowNullValue.- When
true, generated code throws aDisallowedNullValueExceptionif the corresponding keys exist in the JSON map, but its value isnull. - Will be captured and wrapped in a
CheckedFromJsonExceptionifcheckedis enabled injson_serializable.
- When
-
Added support for
Uriconversion. -
Added missing
checkedparameter to theJsonSerializableGenerator.withDefaultHelpersconstructor. -
Added
explicit_to_jsonconfiguration option.- See
JsonSerializableGenerator.explicitToJsonfor details.
- See
-
Added
generate_to_json_functionconfiguration option.- See
JsonSerializableGenerator.generateToJsonFunctionfor details.
- See
0.5.6 #
- Added support for
JsonSerializable.disallowUnrecognizedKeys.- Throws an
UnrecognizedKeysExceptionif it finds unrecognized keys in the JSON map used to populate the annotated field. - Will be captured and wrapped in a
CheckedFromJsonExceptionifcheckedis enabled injson_serializable.
- Throws an
- All
fromJsonconstructors now use block syntax instead of fat arrows.
0.5.5 #
-
Added support for
JsonKey.defaultValue. -
enumdeserialization now uses helpers provided byjson_annotation. -
Small change to how nullable
Mapvalues are deserialized. -
Small whitespace changes to
JsonLiteralgeneration to align withdartfmt. -
Improve detection of
toJsonandfromJsonin nested types.
0.5.4+1 #
- Fixed a bug introduced in
0.5.4in some cases where enum values are nested in collections.
0.5.4 #
-
Add
checkedconfiguration option. Iftrue, generatedfromJsonfunctions include extra checks to validate proper deserialization of types. -
Added
any_mapto configuration. AllowsfromJsoncode to support dynamicMapinstances that are not explicitlyMap<String, dynaimc>. -
Added support for classes with type arguments.
-
Use
Map.mapfor more map conversions. Simplifies generated code and fixes a subtle issue when theMapkey type isdynamicorObject.
0.5.3 #
-
Require the latest version of
package:analyzer-v0.32.0. -
If
JsonKey.fromJsonfunction parameter isIterableorMapwith type arguments ofdynamicorObject, omit the arguments when generating a cast._myHelper(json['key'] as Map)instead of_myHelper(json['key'] as Map<dynamic, dynamic>). -
JsonKey.fromJson/.toJsonnow support functions with optional arguments.
0.5.2 #
- If
JsonKey.fromJson/toJsonare set, apply them before any custom or defaultTypeHelperinstances. This allows customDateTimeparsing, by preempting the existingDateTimeTypeHelper.
0.5.1 #
-
Support new
fromJsonandtoJsonfields onJsonKey. -
Use
logexposed bypackage:build. This requires end-users to have at leastpackage:build_runner^0.8.2. -
Updated minimum
package:source_gendependency to0.8.1which includes improved error messages.
0.5.0 #
-
BREAKING Removed deprecated support for
require_library_directive/requireLibraryDirectiveinbuild_runnerconfiguration. -
BREAKING Removed the deprecated
generators.dartlibrary. -
BREAKING Removed
jsonPartBuilderfunction from public API. -
Support the latest
package:source_gen. -
Private and ignored fields are now excluded when generating serialization and deserialization code by using
@JsonKey(ignore: true). -
Throw an exception if a private field or an ignored field is referenced by a required constructor argument.
-
More comprehensive escaping of string literals.
package:json_serializable/type_helper.dart #
-
Breaking The
nullableparameter onTypeHelper.serializeand.deserializehas been removed. It is now exposed inSerializeContextandDeserializeContextabstract classes as a read-only property. -
Potentially Breaking The
metadataproperty onSerializeContextandDeserializeContextis now readonly. This would potentially break code that extends these classes – which is not expected.
0.4.0 #
-
Potentially Breaking Inherited fields are now processed and used when generating serialization and deserialization code. There is a possibility that the generated code may change in undesired ways for classes annotated for
v0.3. -
Avoid unnecessary braces in string escapes.
-
Use single quotes when generating code.
0.3.2 #
- The
require_library_directiveoption now defaults tofalse. The option will be removed entirely in0.4.0.
0.3.1+2 #
- Support the latest version of the
analyzerpackage.
0.3.1+1 #
- Expanded
package:buildsupport to allow version0.12.0.
0.3.1 #
-
Add a
build.yamlso the builder can be consumed by users ofbuild_runnerversion 0.7.0. -
Now requires a Dart
2.0.0-devrelease.
0.3.0 #
-
NEW top-level library
json_serializable.dart.-
Replaces now deprecated
generators.dartto accessJsonSerializableGeneratorandJsonLiteralGenerator. -
Adds the
jsonPartBuilderfunction to make it easy to create aPartBuilder, without creating an explicit dependency onsource_gen.
-
-
BREAKING
UnsupportedTypeErroradded a new required constructor argument:reason. -
BREAKING The deprecated
annotations.dartlibrary has been removed. Usepackage:json_annotationinstead. -
BREAKING The arguments to
TypeHelperserializeanddeserializehave changed.SerializeContextandDeserializeContext(new classes) are now passed instead of theTypeHelperGeneratortypedef (which has been deleted).
-
JsonSerializableGeneratornow supports an optionaluseWrappersargument when generates and uses wrapper classes to (hopefully) improve the speed and memory usage of serialization – at the cost of more code.NOTE:
useWrappersis not guaranteed to improve the performance of serialization. Benchmarking is recommended. -
Make
nullfield handling smarter. If a field is classified as notnullable, then use this knowledge when generating serialization code – even ifincludeIfNullisfalse.
0.2.5 #
-
Throw an exception if a duplicate JSON key is detected.
-
Support the
nullablefield on theJsonSerializableclass annotation.
0.2.4+1 #
- Throw a more helpful error when a constructor is missing.
0.2.4 #
-
Moved the annotations in
annotations.darttopackage:json_annotations.- Allows package authors to release code that has the corresponding annotations without requiring package users to inherit all the transitive dependencies.
-
Deprecated
annotations.dart.
0.2.3 #
- Write out
toJsonmethods more efficiently when the first fields written are not intercepted by the null-checking method.
0.2.2+1 #
-
Simplify the serialization of
Mapinstances when no conversion is required forvalues. -
Handle
intliterals in JSON being assigned todoublefields.
0.2.2 #
- Enable support for
enumvalues. - Added
asConsttoJsonLiteral. - Improved the handling of Dart-specific characters in JSON strings.
0.2.1 #
- Upgrade to
package:source_genv0.7.0
0.2.0+1 #
- When serializing classes that implement their own
fromJsonconstructor, honor their constructor parameter type.
0.2.0 #
-
BREAKING Types are now segmented into their own libraries.
-
package:json_serializable/generators.dartcontainsGeneratorimplementations. -
package:json_serializable/annotations.dartcontains annotations. This library should be imported with your target classes. -
package:json_serializable/type_helpers.dartcontainsTypeHelperclasses and related helpers which allow custom generation for specific types.
-
-
BREAKING Generation fails for types that are not a JSON primitive or that do not explicitly support JSON serialization.
-
BREAKING
TypeHelper:-
Removed
canmethods. Returnnullfrom(de)serializeif the provided type is not supported. -
Added
(de)serializeNestedarguments to(de)serializemethods allowing generic types. This is how support forIterable,List, andMapis implemented.
-
-
BREAKING
JsonKey.jsonNamewas renamed tonameand is now a named parameter. -
Added support for optional, non-nullable fields.
-
Added support for excluding
nullvalues when generating JSON. -
Eliminated all implicit casts in generated code. These would end up being runtime checks in most cases.
-
Provide a helpful error when generation fails due to undefined types.
0.1.0+1 #
- Fix homepage in
pubspec.yaml.
0.1.0 #
-
Split off from source_gen.
-
Add
/* unsafe */comments to generated output likely to be unsafe. -
Support (de)serializing values in
Map. -
Fix ordering of fields when they are initialized via constructor.
-
Don't use static members when calculating fields to (de)serialize.



